Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Add more UT for range query
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-chen committed Aug 11, 2020
1 parent 1a332fa commit e950412
Showing 1 changed file with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.amazon.opendistroforelasticsearch.sql.expression.Expression;
import com.amazon.opendistroforelasticsearch.sql.expression.FunctionExpression;
import com.amazon.opendistroforelasticsearch.sql.expression.config.ExpressionConfig;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
Expand Down Expand Up @@ -84,21 +86,27 @@ void can_build_query_for_equality_expression() {

@Test
void can_build_query_for_comparison_expression() {
assertEquals(
"{\n"
+ " \"range\" : {\n"
+ " \"age\" : {\n"
+ " \"from\" : 30,\n"
+ " \"to\" : null,\n"
+ " \"include_lower\" : false,\n"
+ " \"include_upper\" : true,\n"
+ " \"boost\" : 1.0\n"
+ " }\n"
+ " }\n"
+ "}",
buildQuery(
dsl.greater(
ref("age", INTEGER), literal(30))));
Expression[] params = {ref("age", INTEGER), literal(30)};
Map<Expression, Object[]> ranges = ImmutableMap.of(
dsl.less(params), new Object[]{null, 30, true, false},
dsl.greater(params), new Object[]{30, null, false, true},
dsl.lte(params), new Object[]{null, 30, true, true},
dsl.gte(params), new Object[]{30, null, true, true});

ranges.forEach((expr, range) ->
assertEquals(
"{\n"
+ " \"range\" : {\n"
+ " \"age\" : {\n"
+ " \"from\" : " + range[0] + ",\n"
+ " \"to\" : " + range[1] + ",\n"
+ " \"include_lower\" : " + range[2] + ",\n"
+ " \"include_upper\" : " + range[3] + ",\n"
+ " \"boost\" : 1.0\n"
+ " }\n"
+ " }\n"
+ "}",
buildQuery(expr)));
}

@Test
Expand Down

0 comments on commit e950412

Please sign in to comment.