Skip to content

Commit 9629ea7

Browse files
committed
remove useless change and resolve comment
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent 518acb2 commit 9629ea7

7 files changed

Lines changed: 75 additions & 49 deletions

File tree

core/src/main/java/org/opensearch/sql/ast/expression/SearchGroup.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public String toQueryString() {
2828

2929
@Override
3030
public String toAnonymizedString() {
31+
if (expression instanceof SearchGroup) {
32+
return expression.toAnonymizedString();
33+
}
3134
return "(" + expression.toAnonymizedString() + ")";
3235
}
3336

core/src/main/java/org/opensearch/sql/ast/tree/Search.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.google.common.collect.ImmutableList;
99
import java.util.List;
10+
import javax.annotation.Nullable;
1011
import lombok.EqualsAndHashCode;
1112
import lombok.Getter;
1213
import lombok.RequiredArgsConstructor;
@@ -27,7 +28,12 @@ public class Search extends UnresolvedPlan {
2728
@EqualsAndHashCode.Include private final UnresolvedPlan child;
2829
@EqualsAndHashCode.Include private final String queryString;
2930

30-
private final SearchExpression originalExpression;
31+
// Currently it's only for anonymizer
32+
private final @Nullable SearchExpression originalExpression;
33+
34+
public Search(UnresolvedPlan child, String queryString) {
35+
this(child, queryString, null);
36+
}
3137

3238
@Override
3339
public List<UnresolvedPlan> getChild() {

core/src/test/java/org/opensearch/sql/ast/tree/SearchTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class SearchTest {
2929
public void setUp() {
3030
mockChild = mock(UnresolvedPlan.class);
3131
testQueryString = "field1:value1 AND field2:value2";
32-
search = new Search(mockChild, testQueryString, null);
32+
search = new Search(mockChild, testQueryString);
3333
}
3434

3535
@Test
@@ -69,7 +69,7 @@ public void testAccept() {
6969
public void testEquals() {
7070
UnresolvedPlan sameChild = mockChild;
7171
String sameQueryString = testQueryString;
72-
Search sameSearch = new Search(sameChild, sameQueryString, null);
72+
Search sameSearch = new Search(sameChild, sameQueryString);
7373

7474
assertEquals(search, sameSearch);
7575
assertEquals(search, search);
@@ -78,14 +78,14 @@ public void testEquals() {
7878
@Test
7979
public void testNotEqualsWithDifferentChild() {
8080
UnresolvedPlan differentChild = mock(UnresolvedPlan.class);
81-
Search differentSearch = new Search(differentChild, testQueryString, null);
81+
Search differentSearch = new Search(differentChild, testQueryString);
8282

8383
assertNotEquals(search, differentSearch);
8484
}
8585

8686
@Test
8787
public void testNotEqualsWithDifferentQueryString() {
88-
Search differentSearch = new Search(mockChild, "different:query", null);
88+
Search differentSearch = new Search(mockChild, "different:query");
8989

9090
assertNotEquals(search, differentSearch);
9191
}
@@ -102,14 +102,14 @@ public void testNotEqualsWithDifferentClass() {
102102

103103
@Test
104104
public void testHashCode() {
105-
Search sameSearch = new Search(mockChild, testQueryString, null);
105+
Search sameSearch = new Search(mockChild, testQueryString);
106106
assertEquals(search.hashCode(), sameSearch.hashCode());
107107
}
108108

109109
@Test
110110
public void testHashCodeWithDifferentValues() {
111111
UnresolvedPlan differentChild = mock(UnresolvedPlan.class);
112-
Search differentSearch = new Search(differentChild, "different:query", null);
112+
Search differentSearch = new Search(differentChild, "different:query");
113113
assertNotEquals(search.hashCode(), differentSearch.hashCode());
114114
}
115115

@@ -123,22 +123,22 @@ public void testToString() {
123123

124124
@Test
125125
public void testWithEmptyQueryString() {
126-
Search emptySearch = new Search(mockChild, "", null);
126+
Search emptySearch = new Search(mockChild, "");
127127
assertEquals("", emptySearch.getQueryString());
128128
assertEquals(mockChild, emptySearch.getChild().get(0));
129129
}
130130

131131
@Test
132132
public void testWithComplexQueryString() {
133133
String complexQuery = "(field1:value1 OR field2:value2) AND NOT field3:value3";
134-
Search complexSearch = new Search(mockChild, complexQuery, null);
134+
Search complexSearch = new Search(mockChild, complexQuery);
135135
assertEquals(complexQuery, complexSearch.getQueryString());
136136
}
137137

138138
@Test
139139
public void testWithSpecialCharactersInQueryString() {
140140
String specialCharsQuery = "field:\"value with spaces\" AND field2:value*";
141-
Search specialSearch = new Search(mockChild, specialCharsQuery, null);
141+
Search specialSearch = new Search(mockChild, specialCharsQuery);
142142
assertEquals(specialCharsQuery, specialSearch.getQueryString());
143143
}
144144
}

core/src/test/java/org/opensearch/sql/calcite/CalciteRelNodeVisitorSearchSimpleTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void testSearchNodeStructure() {
5353
Relation relation = new Relation(AstDSL.qualifiedName("test_index"));
5454

5555
// Act
56-
Search searchNode = new Search(relation, queryString, null);
56+
Search searchNode = new Search(relation, queryString);
5757

5858
// Assert
5959
assertNotNull(searchNode);
@@ -70,7 +70,7 @@ public void testSearchWithEmptyQuery() {
7070
Relation relation = new Relation(AstDSL.qualifiedName("test_index"));
7171

7272
// Act
73-
Search searchNode = new Search(relation, queryString, null);
73+
Search searchNode = new Search(relation, queryString);
7474

7575
// Assert
7676
assertEquals("", searchNode.getQueryString());
@@ -84,7 +84,7 @@ public void testSearchWithComplexQuery() {
8484
Relation relation = new Relation(AstDSL.qualifiedName("test_index"));
8585

8686
// Act
87-
Search searchNode = new Search(relation, queryString, null);
87+
Search searchNode = new Search(relation, queryString);
8888

8989
// Assert
9090
assertEquals(queryString, searchNode.getQueryString());
@@ -97,7 +97,7 @@ public void testSearchWithSpecialCharacters() {
9797
Relation relation = new Relation(AstDSL.qualifiedName("test_index"));
9898

9999
// Act
100-
Search searchNode = new Search(relation, queryString, null);
100+
Search searchNode = new Search(relation, queryString);
101101

102102
// Assert
103103
assertEquals(queryString, searchNode.getQueryString());

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@
8080
import org.opensearch.sql.ast.tree.Kmeans;
8181
import org.opensearch.sql.ast.tree.ML;
8282
import org.opensearch.sql.ast.tree.RareTopN.CommandType;
83-
import org.opensearch.sql.ast.tree.Search;
84-
import org.opensearch.sql.ast.tree.UnresolvedPlan;
8583
import org.opensearch.sql.common.antlr.SyntaxCheckException;
8684
import org.opensearch.sql.common.setting.Settings;
8785
import org.opensearch.sql.common.setting.Settings.Key;
@@ -115,7 +113,7 @@ public void setup() {
115113

116114
@Test
117115
public void testSearchCommand() {
118-
assertSearchEqual("search source=t a=1", search(relation("t"), "a:1"));
116+
assertEqual("search source=t a=1", search(relation("t"), "a:1"));
119117
}
120118

121119
@Test
@@ -176,7 +174,7 @@ public void testSearchWithPrometheusQueryRangeWithNamedArguments() {
176174

177175
@Test
178176
public void testSearchCommandString() {
179-
assertSearchEqual("search source=t a=\"a\"", search(relation("t"), "a:a"));
177+
assertEqual("search source=t a=\"a\"", search(relation("t"), "a:a"));
180178
}
181179

182180
@Test
@@ -187,7 +185,7 @@ public void testSearchCommandWithoutSearch() {
187185

188186
@Test
189187
public void testSearchCommandWithFilterBeforeSource() {
190-
assertSearchEqual("search a=1 source=t", search(relation("t"), "a:1"));
188+
assertEqual("search a=1 source=t", search(relation("t"), "a:1"));
191189
}
192190

193191
@Test
@@ -1393,14 +1391,6 @@ protected void assertEqual(String query, Node expectedPlan) {
13931391
assertEquals(expectedPlan, actualPlan);
13941392
}
13951393

1396-
protected void assertSearchEqual(String query, UnresolvedPlan expectedPlan) {
1397-
Node actualPlan = plan(query);
1398-
assertTrue(actualPlan instanceof Search);
1399-
assertTrue(expectedPlan instanceof Search);
1400-
assertEquals(expectedPlan.getChild(), actualPlan.getChild());
1401-
assertEquals(((Search) expectedPlan).getQueryString(), ((Search) actualPlan).getQueryString());
1402-
}
1403-
14041394
protected void assertEqual(String query, String expected) {
14051395
Node expectedPlan = plan(expected);
14061396
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
@@ -73,7 +73,7 @@ public void testLogicalNotExpr() {
7373
assertEqual(
7474
"source=t | where not a=1",
7575
filter(relation("t"), not(compare("=", field("a"), intLiteral(1)))));
76-
assertSearchEqual("source=t not a=1", search(relation("t"), "NOT(a:1)"));
76+
assertEqual("source=t not a=1", search(relation("t"), "NOT(a:1)"));
7777
}
7878

7979
@Test
@@ -83,7 +83,7 @@ public void testLogicalOrExpr() {
8383
filter(
8484
relation("t"),
8585
or(compare("=", field("a"), intLiteral(1)), compare("=", field("b"), intLiteral(2)))));
86-
assertSearchEqual("source=t a=1 or b=2", search(relation("t"), "(a:1 OR b:2)"));
86+
assertEqual("source=t a=1 or b=2", search(relation("t"), "(a:1 OR b:2)"));
8787
}
8888

8989
@Test
@@ -93,7 +93,7 @@ public void testLogicalAndExpr() {
9393
filter(
9494
relation("t"),
9595
and(compare("=", field("a"), intLiteral(1)), compare("=", field("b"), intLiteral(2)))));
96-
assertSearchEqual("source=t a=1 and b=2", search(relation("t"), "(a:1 AND b:2)"));
96+
assertEqual("source=t a=1 and b=2", search(relation("t"), "(a:1 AND b:2)"));
9797
}
9898

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

@@ -130,7 +130,7 @@ public void testLogicalAndOr() {
130130
compare("=", field("b"), intLiteral(2))),
131131
compare("=", field("c"), intLiteral(3))),
132132
compare("=", field("d"), intLiteral(4)))));
133-
assertSearchEqual(
133+
assertEqual(
134134
"source=t a=1 and b=2 and c=3 or d=4",
135135
search(relation("t"), "((a:1 AND b:2) AND (c:3 OR d:4))"));
136136
}
@@ -149,7 +149,7 @@ public void testLogicalParenthetic() {
149149
compare("=", field("c"), intLiteral(3)),
150150
compare("=", field("d"), intLiteral(4))))));
151151

152-
assertSearchEqual(
152+
assertEqual(
153153
"source=t (a=1 or b=2) and (c=3 or d=4)",
154154
search(relation("t"), "(((a:1 OR b:2)) AND ((c:3 OR d:4)))"));
155155
}
@@ -416,14 +416,14 @@ public void testCompareExpr() {
416416
assertEqual(
417417
"source=t | where a='b'",
418418
filter(relation("t"), compare("=", field("a"), stringLiteral("b"))));
419-
assertSearchEqual("source=t a='b'", search(relation("t"), "a:b"));
419+
assertEqual("source=t a='b'", search(relation("t"), "a:b"));
420420
}
421421

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

429429
@Test
@@ -455,7 +455,7 @@ public void testMixedEqualOperators() {
455455

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

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

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

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

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

@@ -950,39 +950,39 @@ public void testLongLiteralExpr() {
950950

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

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

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

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

983983
@Test
984984
public void testBackQuotedFieldNames() {
985-
assertSearchEqual("source=t `first name`=true", search(relation("t"), "first\\ name:true"));
985+
assertEqual("source=t `first name`=true", search(relation("t"), "first\\ name:true"));
986986
assertEqual(
987987
"source=t | where `first name`=true",
988988
filter(relation("t"), compare("=", field("first name"), booleanLiteral(true))));
@@ -1370,23 +1370,23 @@ public void testMedianAggFuncExpr() {
13701370

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

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

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

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

0 commit comments

Comments
 (0)