Skip to content

Commit d19c147

Browse files
committed
fix UT
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent 6a41ad0 commit d19c147

3 files changed

Lines changed: 39 additions & 27 deletions

File tree

ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLSearchTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ public void testSearchWithFilter() {
4545
String ppl = "search source=EMP DEPTNO=20";
4646
RelNode root = getRelNode(ppl);
4747
String expectedLogical =
48-
"LogicalFilter(condition=[query_string(MAP('query', 'DEPTNO:20':VARCHAR))])\n"
48+
"LogicalFilter(condition=[match(MAP('field_name', $7), MAP('value', '20':VARCHAR))])\n"
4949
+ " LogicalTableScan(table=[[scott, EMP]])\n";
5050
verifyLogical(root, expectedLogical);
5151

5252
String expectedSparkSql =
53-
"SELECT *\nFROM `scott`.`EMP`\nWHERE `query_string`(MAP ('query', 'DEPTNO:20'))";
53+
"SELECT *\n"
54+
+ "FROM `scott`.`EMP`\n"
55+
+ "WHERE `match`(MAP ('field_name', `DEPTNO`), MAP ('value', '20'))";
5456
verifyPPLToSparkSQL(root, expectedSparkSql);
5557
}
5658

ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@
7777
import org.opensearch.sql.ast.tree.Kmeans;
7878
import org.opensearch.sql.ast.tree.ML;
7979
import org.opensearch.sql.ast.tree.RareTopN.CommandType;
80+
import org.opensearch.sql.ast.tree.Search;
8081
import org.opensearch.sql.ast.tree.Timechart;
82+
import org.opensearch.sql.ast.tree.UnresolvedPlan;
8183
import org.opensearch.sql.common.antlr.SyntaxCheckException;
8284
import org.opensearch.sql.common.setting.Settings;
8385
import org.opensearch.sql.common.setting.Settings.Key;
@@ -111,7 +113,7 @@ public void setup() {
111113

112114
@Test
113115
public void testSearchCommand() {
114-
assertEqual("search source=t a=1", search(relation("t"), "a:1"));
116+
assertSearchEqual("search source=t a=1", search(relation("t"), "a:1"));
115117
}
116118

117119
@Test
@@ -172,7 +174,7 @@ public void testSearchWithPrometheusQueryRangeWithNamedArguments() {
172174

173175
@Test
174176
public void testSearchCommandString() {
175-
assertEqual("search source=t a=\"a\"", search(relation("t"), "a:a"));
177+
assertSearchEqual("search source=t a=\"a\"", search(relation("t"), "a:a"));
176178
}
177179

178180
@Test
@@ -183,7 +185,7 @@ public void testSearchCommandWithoutSearch() {
183185

184186
@Test
185187
public void testSearchCommandWithFilterBeforeSource() {
186-
assertEqual("search a=1 source=t", search(relation("t"), "a:1"));
188+
assertSearchEqual("search a=1 source=t", search(relation("t"), "a:1"));
187189
}
188190

189191
@Test
@@ -1347,6 +1349,14 @@ protected void assertEqual(String query, Node expectedPlan) {
13471349
assertEquals(expectedPlan, actualPlan);
13481350
}
13491351

1352+
protected void assertSearchEqual(String query, UnresolvedPlan expectedPlan) {
1353+
Node actualPlan = plan(query);
1354+
assertTrue(actualPlan instanceof Search);
1355+
assertTrue(expectedPlan instanceof Search);
1356+
assertEquals(expectedPlan.getChild(), actualPlan.getChild());
1357+
assertEquals(((Search) expectedPlan).getQueryString(), ((Search) actualPlan).getQueryString());
1358+
}
1359+
13501360
protected void assertEqual(String query, String expected) {
13511361
Node expectedPlan = plan(expected);
13521362
assertEqual(query, expectedPlan);

ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void testLogicalNotExpr() {
7272
assertEqual(
7373
"source=t | where not a=1",
7474
filter(relation("t"), not(compare("=", field("a"), intLiteral(1)))));
75-
assertEqual("source=t not a=1", search(relation("t"), "NOT(a:1)"));
75+
assertSearchEqual("source=t not a=1", search(relation("t"), "NOT(a:1)"));
7676
}
7777

7878
@Test
@@ -82,7 +82,7 @@ public void testLogicalOrExpr() {
8282
filter(
8383
relation("t"),
8484
or(compare("=", field("a"), intLiteral(1)), compare("=", field("b"), intLiteral(2)))));
85-
assertEqual("source=t a=1 or b=2", search(relation("t"), "(a:1 OR b:2)"));
85+
assertSearchEqual("source=t a=1 or b=2", search(relation("t"), "(a:1 OR b:2)"));
8686
}
8787

8888
@Test
@@ -92,7 +92,7 @@ public void testLogicalAndExpr() {
9292
filter(
9393
relation("t"),
9494
and(compare("=", field("a"), intLiteral(1)), compare("=", field("b"), intLiteral(2)))));
95-
assertEqual("source=t a=1 and b=2", search(relation("t"), "(a:1 AND b:2)"));
95+
assertSearchEqual("source=t a=1 and b=2", search(relation("t"), "(a:1 AND b:2)"));
9696
}
9797

9898
@Test
@@ -102,8 +102,8 @@ public void testLogicalAndExprWithoutKeywordAnd() {
102102
filter(
103103
relation("t"),
104104
and(compare("=", field("a"), intLiteral(1)), compare("=", field("b"), intLiteral(2)))));
105-
assertEqual("source=t a=1 b=2", search(relation("t"), "(a:1) AND (b:2)"));
106-
assertEqual(
105+
assertSearchEqual("source=t a=1 b=2", search(relation("t"), "(a:1) AND (b:2)"));
106+
assertSearchEqual(
107107
"source=t a=1 b=2 c=2 text", search(relation("t"), "(a:1) AND (b:2) AND (c:2) AND (text)"));
108108
}
109109

@@ -129,7 +129,7 @@ public void testLogicalAndOr() {
129129
compare("=", field("b"), intLiteral(2))),
130130
compare("=", field("c"), intLiteral(3))),
131131
compare("=", field("d"), intLiteral(4)))));
132-
assertEqual(
132+
assertSearchEqual(
133133
"source=t a=1 and b=2 and c=3 or d=4",
134134
search(relation("t"), "((a:1 AND b:2) AND (c:3 OR d:4))"));
135135
}
@@ -148,7 +148,7 @@ public void testLogicalParenthetic() {
148148
compare("=", field("c"), intLiteral(3)),
149149
compare("=", field("d"), intLiteral(4))))));
150150

151-
assertEqual(
151+
assertSearchEqual(
152152
"source=t (a=1 or b=2) and (c=3 or d=4)",
153153
search(relation("t"), "(((a:1 OR b:2)) AND ((c:3 OR d:4)))"));
154154
}
@@ -415,14 +415,14 @@ public void testCompareExpr() {
415415
assertEqual(
416416
"source=t | where a='b'",
417417
filter(relation("t"), compare("=", field("a"), stringLiteral("b"))));
418-
assertEqual("source=t a='b'", search(relation("t"), "a:b"));
418+
assertSearchEqual("source=t a='b'", search(relation("t"), "a:b"));
419419
}
420420

421421
@Test
422422
public void testCompareFieldsExpr() {
423423
assertEqual(
424424
"source=t | where a>b", filter(relation("t"), compare(">", field("a"), field("b"))));
425-
assertEqual("source=t a>b", search(relation("t"), "a:>b"));
425+
assertSearchEqual("source=t a>b", search(relation("t"), "a:>b"));
426426
}
427427

428428
@Test
@@ -454,7 +454,7 @@ public void testMixedEqualOperators() {
454454

455455
@Test
456456
public void testInExpr() {
457-
assertEqual("source=t f in (1, 2, 3)", search(relation("t"), "f:( 1 OR 2 OR 3 )"));
457+
assertSearchEqual("source=t f in (1, 2, 3)", search(relation("t"), "f:( 1 OR 2 OR 3 )"));
458458

459459
assertEqual(
460460
"source=t | where f in (1, 2, 3)",
@@ -913,7 +913,7 @@ public void testNestedFieldNameWithSpecialChars() {
913913

914914
@Test
915915
public void testStringLiteralExpr() {
916-
assertEqual("source=t a=\"string\"", search(relation("t"), "a:string"));
916+
assertSearchEqual("source=t a=\"string\"", search(relation("t"), "a:string"));
917917
assertEqual(
918918
"source=t | where a=\"string\"",
919919
filter(relation("t"), compare("=", field("a"), stringLiteral("string"))));
@@ -929,12 +929,12 @@ public void testIntegerLiteralExpr() {
929929
compare("=", field("a"), intLiteral(1)),
930930
compare("=", field("b"), intLiteral(-1)))));
931931

932-
assertEqual("source=t a=1 b=-1", search(relation("t"), "(a:1) AND (b:-1)"));
932+
assertSearchEqual("source=t a=1 b=-1", search(relation("t"), "(a:1) AND (b:-1)"));
933933
}
934934

935935
@Test
936936
public void testLongLiteralExpr() {
937-
assertEqual(
937+
assertSearchEqual(
938938
"source=t a=1234567890123 b=-1234567890123",
939939
search(relation("t"), "(a:1234567890123) AND (b:-1234567890123)"));
940940

@@ -949,39 +949,39 @@ public void testLongLiteralExpr() {
949949

950950
@Test
951951
public void testDoubleLiteralExpr() {
952-
assertEqual("source=t b=0.1d", search(relation("t"), "b:0.1"));
952+
assertSearchEqual("source=t b=0.1d", search(relation("t"), "b:0.1"));
953953
assertEqual(
954954
"source=t | where b=0.1d",
955955
filter(relation("t"), compare("=", field("b"), doubleLiteral(0.1))));
956956
}
957957

958958
@Test
959959
public void testFloatLiteralExpr() {
960-
assertEqual("source=t b=0.1f", search(relation("t"), "b:0.1"));
960+
assertSearchEqual("source=t b=0.1f", search(relation("t"), "b:0.1"));
961961
assertEqual(
962962
"source=t | where b=0.1f",
963963
filter(relation("t"), compare("=", field("b"), floatLiteral(0.1f))));
964964
}
965965

966966
@Test
967967
public void testDecimalLiteralExpr() {
968-
assertEqual("source=t b=0.1", search(relation("t"), "b:0.1"));
968+
assertSearchEqual("source=t b=0.1", search(relation("t"), "b:0.1"));
969969
assertEqual(
970970
"source=t | where b=0.1",
971971
filter(relation("t"), compare("=", field("b"), decimalLiteral(0.1))));
972972
}
973973

974974
@Test
975975
public void testBooleanLiteralExpr() {
976-
assertEqual("source=t a=true", search(relation("t"), "a:true"));
976+
assertSearchEqual("source=t a=true", search(relation("t"), "a:true"));
977977
assertEqual(
978978
"source=t | where a=true",
979979
filter(relation("t"), compare("=", field("a"), booleanLiteral(true))));
980980
}
981981

982982
@Test
983983
public void testBackQuotedFieldNames() {
984-
assertEqual("source=t `first name`=true", search(relation("t"), "first\\ name:true"));
984+
assertSearchEqual("source=t `first name`=true", search(relation("t"), "first\\ name:true"));
985985
assertEqual(
986986
"source=t | where `first name`=true",
987987
filter(relation("t"), compare("=", field("first name"), booleanLiteral(true))));
@@ -1369,23 +1369,23 @@ public void testMedianAggFuncExpr() {
13691369

13701370
@Test
13711371
public void testTimeModifierEarliestWithNumericValue() {
1372-
assertEqual("source=t earliest=1", search(relation("t"), "@timestamp:>=1000"));
1372+
assertSearchEqual("source=t earliest=1", search(relation("t"), "@timestamp:>=1000"));
13731373

1374-
assertEqual(
1374+
assertSearchEqual(
13751375
"source=t earliest=1754020061.123456",
13761376
search(relation("t"), "@timestamp:>=1754020061123.456"));
13771377
}
13781378

13791379
@Test
13801380
public void testTimeModifierLatestWithNowValue() {
1381-
assertEqual(
1381+
assertSearchEqual(
13821382
"source=t earliest=now latest=now()",
13831383
search(relation("t"), "(@timestamp:>=now) AND (@timestamp:<=now)"));
13841384
}
13851385

13861386
@Test
13871387
public void testTimeModifierEarliestWithStringValue() {
1388-
assertEqual(
1388+
assertSearchEqual(
13891389
"source=t earliest='2025-12-10 14:00:00'",
13901390
search(relation("t"), "@timestamp:>=2025\\-12\\-10T14\\:00\\:00Z"));
13911391
}

0 commit comments

Comments
 (0)