Skip to content

Commit 3b0afb8

Browse files
committed
fix IT and apply spotless
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent df9f5dd commit 3b0afb8

27 files changed

Lines changed: 117 additions & 64 deletions

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLBasicIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testMultipleSourceQuery_SameTable() {
6464

6565
@Test
6666
public void testMultipleSourceQuery_DifferentTables() {
67-
JSONObject actual = executeQuery("source=test, test1");
67+
JSONObject actual = executeQuery("source=test, test1 | fields name, alias, age");
6868
verifySchema(
6969
actual, schema("name", "string"), schema("age", "long"), schema("alias", "string"));
7070
verifyDataRows(
@@ -73,7 +73,7 @@ public void testMultipleSourceQuery_DifferentTables() {
7373

7474
@Test
7575
public void testIndexPatterns() {
76-
JSONObject actual = executeQuery("source=test*");
76+
JSONObject actual = executeQuery("source=test* | fields name, alias, age");
7777
verifySchema(
7878
actual, schema("name", "string"), schema("age", "long"), schema("alias", "string"));
7979
verifyDataRows(

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLCaseFunctionIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void testCaseWhenWithCast() {
6767
cast(response as int) >= 500 AND cast(response as int) < 600, "Server Error"
6868
else concat("Incorrect HTTP status code for", url))
6969
| where status != "Success"
70+
| fields host, method, bytes, response, url, status
7071
""",
7172
TEST_INDEX_WEBLOGS));
7273
verifySchema(
@@ -111,6 +112,7 @@ public void testCaseWhenNoElse() {
111112
cast(response as int) >= 400 AND cast(response as int) < 500, "Client Error",
112113
cast(response as int) >= 500 AND cast(response as int) < 600, "Server Error")
113114
| where isnull(status) OR status != "Success"
115+
| fields host, method, bytes, response, url, status
114116
""",
115117
TEST_INDEX_WEBLOGS));
116118
verifySchema(
@@ -150,6 +152,7 @@ response in ('400', '403'), "Client Error",
150152
response in ('500', '505'), "Server Error"
151153
else concat("Incorrect HTTP status code for", url))
152154
| where status != "Success"
155+
| fields host, method, bytes, response, url, status
153156
""",
154157
TEST_INDEX_WEBLOGS));
155158
verifySchema(
@@ -194,6 +197,7 @@ response in ('300', '301'), false,
194197
response in ('400', '403'), false,
195198
response in ('500', '505'), false
196199
else false)
200+
| fields host, method, bytes, response, url
197201
""",
198202
TEST_INDEX_WEBLOGS));
199203
verifySchema(
@@ -228,6 +232,7 @@ response in ('500', '505'), "500"
228232
else concat("Incorrect HTTP status code for", url))
229233
| fields new_response
230234
]
235+
| fields host, method, bytes, response, url
231236
""",
232237
TEST_INDEX_WEBLOGS, TEST_INDEX_WEBLOGS));
233238
verifySchema(

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLDedupIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void testReorderDedupFieldsShouldNotAffectResult() {
242242
executeQuery(
243243
String.format(
244244
"""
245-
source=%s | dedup 2 name, category
245+
source=%s | dedup 2 name, category | fields name, category, id
246246
""",
247247
TEST_INDEX_DUPLICATION_NULLABLE));
248248
verifySchemaInOrder(
@@ -254,7 +254,7 @@ public void testReorderDedupFieldsShouldNotAffectResult() {
254254
executeQuery(
255255
String.format(
256256
"""
257-
source=%s | dedup 2 category, name
257+
source=%s | dedup 2 category, name | fields name, category, id
258258
""",
259259
TEST_INDEX_DUPLICATION_NULLABLE));
260260
verifySchemaInOrder(
@@ -266,7 +266,7 @@ public void testReorderDedupFieldsShouldNotAffectResult() {
266266
executeQuery(
267267
String.format(
268268
"""
269-
source=%s | dedup 2 name, category KEEPEMPTY=true
269+
source=%s | dedup 2 name, category KEEPEMPTY=true | fields name, category, id
270270
""",
271271
TEST_INDEX_DUPLICATION_NULLABLE));
272272
verifySchemaInOrder(
@@ -278,7 +278,7 @@ public void testReorderDedupFieldsShouldNotAffectResult() {
278278
executeQuery(
279279
String.format(
280280
"""
281-
source=%s | dedup 2 category, name KEEPEMPTY=true
281+
source=%s | dedup 2 category, name KEEPEMPTY=true | fields name, category, id
282282
""",
283283
TEST_INDEX_DUPLICATION_NULLABLE));
284284
verifySchemaInOrder(

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLEventstatsIT.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testEventstat() {
3636
executeQuery(
3737
String.format(
3838
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
39-
+ " as max",
39+
+ " as max | fields name, country, state, month, year, age, cnt, avg, min, max",
4040
TEST_INDEX_STATE_COUNTRY));
4141

4242
verifySchemaInOrder(
@@ -66,7 +66,7 @@ public void testEventstatWithNull() {
6666
executeQuery(
6767
String.format(
6868
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
69-
+ " as max",
69+
+ " as max | fields name, country, state, month, year, age, cnt, avg, min, max",
7070
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
7171

7272
verifySchemaInOrder(
@@ -98,7 +98,8 @@ public void testEventstatBy() {
9898
executeQuery(
9999
String.format(
100100
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
101-
+ " as max by country",
101+
+ " as max by country | fields name, country, state, month, year, age, cnt,"
102+
+ " avg, min, max",
102103
TEST_INDEX_STATE_COUNTRY));
103104

104105
verifySchemaInOrder(
@@ -128,7 +129,8 @@ public void testEventstatByWithNull() {
128129
executeQuery(
129130
String.format(
130131
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
131-
+ " as max by country",
132+
+ " as max by country | fields name, country, state, month, year, age, cnt,"
133+
+ " avg, min, max",
132134
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
133135

134136
verifySchemaInOrder(
@@ -157,7 +159,8 @@ public void testEventstatByWithNull() {
157159
executeQuery(
158160
String.format(
159161
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
160-
+ " as max by state",
162+
+ " as max by state | fields name, country, state, month, year, age, cnt, avg,"
163+
+ " min, max",
161164
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
162165
verifyDataRows(
163166
actual,
@@ -175,7 +178,8 @@ public void testEventstatBySpan() {
175178
executeQuery(
176179
String.format(
177180
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
178-
+ " as max by span(age, 10) as age_span",
181+
+ " as max by span(age, 10) as age_span | fields name, country, state, month,"
182+
+ " year, age, cnt, avg, min, max",
179183
TEST_INDEX_STATE_COUNTRY));
180184

181185
verifyDataRows(
@@ -192,7 +196,8 @@ public void testEventstatBySpanWithNull() {
192196
executeQuery(
193197
String.format(
194198
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
195-
+ " as max by span(age, 10) as age_span",
199+
+ " as max by span(age, 10) as age_span | fields name, country, state, month,"
200+
+ " year, age, cnt, avg, min, max",
196201
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
197202

198203
verifyDataRows(
@@ -211,7 +216,8 @@ public void testEventstatByMultiplePartitions1() {
211216
executeQuery(
212217
String.format(
213218
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
214-
+ " as max by span(age, 10) as age_span, country",
219+
+ " as max by span(age, 10) as age_span, country | fields name, country, state,"
220+
+ " month, year, age, cnt, avg, min, max",
215221
TEST_INDEX_STATE_COUNTRY));
216222

217223
verifyDataRows(
@@ -228,7 +234,8 @@ public void testEventstatByMultiplePartitions2() {
228234
executeQuery(
229235
String.format(
230236
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
231-
+ " as max by span(age, 10) as age_span, state",
237+
+ " as max by span(age, 10) as age_span, state | fields name, country, state,"
238+
+ " month, year, age, cnt, avg, min, max",
232239
TEST_INDEX_STATE_COUNTRY));
233240

234241
verifyDataRows(
@@ -245,7 +252,8 @@ public void testEventstatByMultiplePartitionsWithNull1() {
245252
executeQuery(
246253
String.format(
247254
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
248-
+ " as max by span(age, 10) as age_span, country",
255+
+ " as max by span(age, 10) as age_span, country | fields name, country, state,"
256+
+ " month, year, age, cnt, avg, min, max",
249257
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
250258

251259
verifyDataRows(
@@ -264,7 +272,8 @@ public void testEventstatByMultiplePartitionsWithNull2() {
264272
executeQuery(
265273
String.format(
266274
"source=%s | eventstats count() as cnt, avg(age) as avg, min(age) as min, max(age)"
267-
+ " as max by span(age, 10) as age_span, state",
275+
+ " as max by span(age, 10) as age_span, state | fields name, country, state,"
276+
+ " month, year, age, cnt, avg, min, max",
268277
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
269278

270279
verifyDataRows(
@@ -320,7 +329,8 @@ public void testMultipleEventstat() {
320329
executeQuery(
321330
String.format(
322331
"source=%s | eventstats avg(age) as avg_age by state, country | eventstats"
323-
+ " avg(avg_age) as avg_state_age by country",
332+
+ " avg(avg_age) as avg_state_age by country | fields name, country, state,"
333+
+ " month, year, age, avg_age, avg_state_age",
324334
TEST_INDEX_STATE_COUNTRY));
325335

326336
verifyDataRows(
@@ -337,7 +347,8 @@ public void testMultipleEventstatWithNull() {
337347
executeQuery(
338348
String.format(
339349
"source=%s | eventstats avg(age) as avg_age by state, country | eventstats"
340-
+ " avg(avg_age) as avg_state_age by country",
350+
+ " avg(avg_age) as avg_state_age by country | fields name, country, state,"
351+
+ " month, year, age, avg_age, avg_state_age",
341352
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
342353

343354
verifyDataRows(
@@ -358,7 +369,9 @@ public void testMultipleEventstatWithEval() {
358369
"source=%s | eventstats avg(age) as avg_age by country, state, name | eval"
359370
+ " avg_age_divide_20 = avg_age - 20 | eventstats avg(avg_age_divide_20) as"
360371
+ " avg_state_age by country, state | where avg_state_age > 0 | eventstats"
361-
+ " count(avg_state_age) as count_country_age_greater_20 by country",
372+
+ " count(avg_state_age) as count_country_age_greater_20 by country | fields"
373+
+ " name, country, state, month, year, age, avg_age, avg_age_divide_20,"
374+
+ " avg_state_age, count_country_age_greater_20",
362375
TEST_INDEX_STATE_COUNTRY));
363376

364377
verifyDataRows(
@@ -394,7 +407,8 @@ public void testEventstatVariance() {
394407
executeQuery(
395408
String.format(
396409
"source=%s | eventstats stddev_pop(age), stddev_samp(age), var_pop(age),"
397-
+ " var_samp(age)",
410+
+ " var_samp(age) | fields name, country, state, month, year, age,"
411+
+ " `stddev_pop(age)`, `stddev_samp(age)`, `var_pop(age)`, `var_samp(age)`",
398412
TEST_INDEX_STATE_COUNTRY));
399413

400414
verifySchemaInOrder(
@@ -464,7 +478,8 @@ public void testEventstatVarianceWithNull() {
464478
executeQuery(
465479
String.format(
466480
"source=%s | eventstats stddev_pop(age), stddev_samp(age), var_pop(age),"
467-
+ " var_samp(age)",
481+
+ " var_samp(age) | fields name, country, state, month, year, age,"
482+
+ " `stddev_pop(age)`, `stddev_samp(age)`, `var_pop(age)`, `var_samp(age)`",
468483
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
469484

470485
verifySchemaInOrder(
@@ -527,7 +542,8 @@ public void testEventstatVarianceBy() {
527542
executeQuery(
528543
String.format(
529544
"source=%s | eventstats stddev_pop(age), stddev_samp(age), var_pop(age),"
530-
+ " var_samp(age) by country",
545+
+ " var_samp(age) by country | fields name, country, state, month, year, age,"
546+
+ " `stddev_pop(age)`, `stddev_samp(age)`, `var_pop(age)`, `var_samp(age)`",
531547
TEST_INDEX_STATE_COUNTRY));
532548

533549
verifyDataRows(
@@ -543,7 +559,8 @@ public void testEventstatVarianceBySpan() {
543559
JSONObject actual =
544560
executeQuery(
545561
String.format(
546-
"source=%s | where country != 'USA' | eventstats stddev_samp(age) by span(age, 10)",
562+
"source=%s | where country != 'USA' | eventstats stddev_samp(age) by span(age, 10)"
563+
+ " | fields name, country, state, month, year, age, `stddev_samp(age)`",
547564
TEST_INDEX_STATE_COUNTRY));
548565

549566
verifyDataRows(
@@ -558,7 +575,8 @@ public void testEventstatVarianceWithNullBy() {
558575
executeQuery(
559576
String.format(
560577
"source=%s | eventstats stddev_pop(age), stddev_samp(age), var_pop(age),"
561-
+ " var_samp(age) by country",
578+
+ " var_samp(age) by country | fields name, country, state, month, year, age,"
579+
+ " `stddev_pop(age)`, `stddev_samp(age)`, `var_pop(age)`, `var_samp(age)`",
562580
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
563581

564582
verifyDataRows(

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLInSubqueryIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void testSelfInSubquery() {
5252
| where country = 'USA'
5353
| fields id
5454
]
55+
| fields name, country, occupation, id, salary
5556
""",
5657
TEST_INDEX_WORKER, TEST_INDEX_WORKER));
5758
verifySchema(
@@ -314,6 +315,7 @@ public void testNestedInSubquery2() {
314315
| fields uid
315316
]
316317
| sort - salary
318+
| fields name, country, occupation, id, salary
317319
""",
318320
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION, TEST_INDEX_OCCUPATION));
319321
verifySchema(

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLJoinIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ public void testComplexSemiJoin() {
250250
executeQuery(
251251
String.format(
252252
"source = %s | where country = 'Canada' OR country = 'England' | left semi join"
253-
+ " left=a, right=b ON a.name = b.name %s | sort a.age",
253+
+ " left=a, right=b ON a.name = b.name %s | sort a.age | fields name, country,"
254+
+ " state, month, year, age",
254255
TEST_INDEX_STATE_COUNTRY, TEST_INDEX_OCCUPATION));
255256
verifySchema(
256257
actual,
@@ -272,7 +273,8 @@ public void testComplexAntiJoin() {
272273
executeQuery(
273274
String.format(
274275
"source = %s | where country = 'Canada' OR country = 'England' | left anti join"
275-
+ " left=a, right=b ON a.name = b.name %s | sort a.age",
276+
+ " left=a, right=b ON a.name = b.name %s | sort a.age | fields name, country,"
277+
+ " state, month, year, age",
276278
TEST_INDEX_STATE_COUNTRY, TEST_INDEX_OCCUPATION));
277279
verifySchema(
278280
actual,

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLRenameIT.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import static org.opensearch.sql.util.MatcherUtils.verifySchemaInOrder;
1414

1515
import java.io.IOException;
16+
import java.util.Arrays;
17+
import java.util.HashSet;
18+
import java.util.List;
1619
import org.json.JSONObject;
1720
import org.junit.Test;
1821

@@ -55,7 +58,7 @@ public void testRefRenamedField() {
5558
source = %s | rename age as renamed_age | fields age
5659
""",
5760
TEST_INDEX_STATE_COUNTRY)));
58-
assertEquals(
61+
verifyErrorMessage(
5962
"field [age] not found; input fields are: [name, country, state, month, year, renamed_age,"
6063
+ " _id, _index, _score, _maxscore, _sort, _routing]",
6164
e.getMessage());
@@ -73,7 +76,7 @@ public void testRenameNotExistedField() {
7376
source = %s | rename renamed_age as age
7477
""",
7578
TEST_INDEX_STATE_COUNTRY)));
76-
assertEquals(
79+
verifyErrorMessage(
7780
"field [renamed_age] not found; input fields are: [name, country, state, month, year, age,"
7881
+ " _id, _index, _score, _maxscore, _sort, _routing]",
7982
e.getMessage());
@@ -182,4 +185,19 @@ public void testRenameWithBackticksInAgg() {
182185
verifySchemaInOrder(result, schema("avg(`user_age`)", "double"), schema("country", "string"));
183186
verifyDataRows(result, rows(22.5, "Canada"), rows(50.0, "USA"));
184187
}
188+
189+
private void verifyErrorMessage(String actual, String expected) {
190+
String[] actualList = actual.split("input fields are:");
191+
String[] expectedList = expected.split("input fields are:");
192+
assert actualList.length == expectedList.length;
193+
assert actualList.length == 2;
194+
assert actualList[0].equals(expectedList[0]);
195+
assert transferStringToList(actualList[1]).equals(transferStringToList(expectedList[1]));
196+
}
197+
198+
private HashSet<String> transferStringToList(String listString) {
199+
List<String> list =
200+
Arrays.stream(listString.strip().substring(1, listString.length() - 1).split(",")).toList();
201+
return new HashSet<>(list.stream().map(s -> s.strip()).toList());
202+
}
185203
}

integ-test/src/test/java/org/opensearch/sql/ppl/DataTypeIT.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ public void test_numeric_data_types() throws IOException {
5050

5151
@Test
5252
public void test_nonnumeric_data_types() throws IOException {
53-
JSONObject result = executeQuery(String.format("source=%s", TEST_INDEX_DATATYPE_NONNUMERIC));
53+
JSONObject result =
54+
executeQuery(
55+
String.format(
56+
"source=%s | fields text_value, date_nanos_value, date_value, boolean_value,"
57+
+ " ip_value, nested_value, object_value, keyword_value, geo_point_value,"
58+
+ " binary_value",
59+
TEST_INDEX_DATATYPE_NONNUMERIC));
5460
verifySchemaInOrder(
5561
result,
5662
schema("text_value", "string"),

0 commit comments

Comments
 (0)