Skip to content

Commit 6c7a2b6

Browse files
committed
fix IT by workaround
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent 358d430 commit 6c7a2b6

7 files changed

Lines changed: 74 additions & 35 deletions

File tree

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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void testCaseWhenWithCast() {
6565
" cast(response as int) >= 400 AND cast(response as int) < 500, \"Client Error\",\n" +
6666
" cast(response as int) >= 500 AND cast(response as int) < 600, \"Server Error\"\n" +
6767
" else concat(\"Incorrect HTTP status code for\", url))\n" +
68-
"| where status != \"Success\"\n",
68+
"| where status != \"Success\"\n | fields host, method, bytes, response, url, status",
6969
TEST_INDEX_WEBLOGS));
7070
verifySchema(
7171
actual,
@@ -107,7 +107,7 @@ public void testCaseWhenNoElse() {
107107
" cast(response as int) >= 300 AND cast(response as int) < 400, \"Redirection\",\n" +
108108
" cast(response as int) >= 400 AND cast(response as int) < 500, \"Client Error\",\n" +
109109
" cast(response as int) >= 500 AND cast(response as int) < 600, \"Server Error\")\n" +
110-
"| where isnull(status) OR status != \"Success\"\n",
110+
"| where isnull(status) OR status != \"Success\" | fields host, method, bytes, response, url, status\n",
111111
TEST_INDEX_WEBLOGS));
112112
verifySchema(
113113
actual,
@@ -144,7 +144,7 @@ public void testCaseWhenWithIn() {
144144
" response in ('400', '403'), \"Client Error\",\n" +
145145
" response in ('500', '505'), \"Server Error\"\n" +
146146
" else concat(\"Incorrect HTTP status code for\", url))\n" +
147-
"| where status != \"Success\"\n",
147+
"| where status != \"Success\" | fields host, method, bytes, response, url, status\n",
148148
TEST_INDEX_WEBLOGS));
149149
verifySchema(
150150
actual,
@@ -186,7 +186,7 @@ public void testCaseWhenInFilter() {
186186
" response in ('300', '301'), false,\n" +
187187
" response in ('400', '403'), false,\n" +
188188
" response in ('500', '505'), false\n" +
189-
" else false)\n",
189+
" else false) | fields host, method, bytes, response, url\n",
190190
TEST_INDEX_WEBLOGS));
191191
verifySchema(
192192
actual,
@@ -218,7 +218,7 @@ public void testCaseWhenInSubquery() {
218218
" response in ('500', '505'), \"500\"\n" +
219219
" else concat(\"Incorrect HTTP status code for\", url))\n" +
220220
" | fields new_response\n" +
221-
" ]\n",
221+
" ] | fields host, method, bytes, response, url\n",
222222
TEST_INDEX_WEBLOGS, TEST_INDEX_WEBLOGS));
223223
verifySchema(
224224
actual,

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
@@ -192,31 +192,31 @@ public void testDedupMultipleFieldsKeepEmpty2() {
192192
public void testReorderDedupFieldsShouldNotAffectResult() {
193193
JSONObject actual1 =
194194
executeQuery(
195-
"source=" + TEST_INDEX_DUPLICATION_NULLABLE + " | dedup 2 name, category\n");
195+
"source=" + TEST_INDEX_DUPLICATION_NULLABLE + " | dedup 2 name, category | fields name, category, id\n");
196196
verifySchemaInOrder(
197197
actual1,
198198
schema("name", null, "string"),
199199
schema("category", null, "string"),
200200
schema("id", null, "integer"));
201201
JSONObject actual2 =
202202
executeQuery(
203-
"source=" + TEST_INDEX_DUPLICATION_NULLABLE + " | dedup 2 category, name\n");
203+
"source=" + TEST_INDEX_DUPLICATION_NULLABLE + " | dedup 2 category, name | fields name, category, id\n");
204204
verifySchemaInOrder(
205205
actual2,
206206
schema("name", null, "string"),
207207
schema("category", null, "string"),
208208
schema("id", null, "integer"));
209209
JSONObject actual3 =
210210
executeQuery(
211-
"source=" + TEST_INDEX_DUPLICATION_NULLABLE + " | dedup 2 name, category KEEPEMPTY=true\n");
211+
"source=" + TEST_INDEX_DUPLICATION_NULLABLE + " | dedup 2 name, category KEEPEMPTY=true | fields name, category, id\n");
212212
verifySchemaInOrder(
213213
actual3,
214214
schema("name", null, "string"),
215215
schema("category", null, "string"),
216216
schema("id", null, "integer"));
217217
JSONObject actual4 =
218218
executeQuery(
219-
"source=" + TEST_INDEX_DUPLICATION_NULLABLE + " | dedup 2 category, name KEEPEMPTY=true\n");
219+
"source=" + TEST_INDEX_DUPLICATION_NULLABLE + " | dedup 2 category, name KEEPEMPTY=true | fields name, category, id\n");
220220
verifySchemaInOrder(
221221
actual4,
222222
schema("name", null, "string"),

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void testSelfInSubquery() {
4545
JSONObject result =
4646
executeQuery(
4747
String.format(
48-
" source = %s | where id in [ source = %s| where country = 'USA'| fields id]",
48+
" source = %s | where id in [ source = %s| where country = 'USA'| fields id] | fields name, country, occupation, id, salary",
4949
TEST_INDEX_WORKER, TEST_INDEX_WORKER));
5050
verifySchema(
5151
result,
@@ -233,7 +233,7 @@ public void testNestedInSubquery2() {
233233
" ]\n" +
234234
" | fields uid\n" +
235235
" ]\n" +
236-
"| sort - salary\n",
236+
"| sort - salary | fields name, country, occupation, id, salary\n",
237237
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION, TEST_INDEX_OCCUPATION));
238238
verifySchema(
239239
result,

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

Lines changed: 2 additions & 1 deletion
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,

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
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;
19+
import java.util.stream.Collectors;
20+
1621
import org.json.JSONObject;
1722
import org.junit.Test;
1823

@@ -47,7 +52,7 @@ public void testRefRenamedField() {
4752
() ->
4853
executeQuery(
4954
"source = " + TEST_INDEX_STATE_COUNTRY + " | rename age as renamed_age | fields age\n"));
50-
assertEquals(
55+
verifyErrorMessage(
5156
"field [age] not found; input fields are: [name, country, state, month, year, renamed_age,"
5257
+ " _id, _index, _score, _maxscore, _sort, _routing]",
5358
e.getMessage());
@@ -61,7 +66,7 @@ public void testRenameNotExistedField() {
6166
() ->
6267
executeQuery(
6368
"source = " + TEST_INDEX_STATE_COUNTRY + " | rename renamed_age as age\n"));
64-
assertEquals(
69+
verifyErrorMessage(
6570
"field [renamed_age] not found; input fields are: [name, country, state, month, year, age,"
6671
+ " _id, _index, _score, _maxscore, _sort, _routing]",
6772
e.getMessage());
@@ -148,4 +153,19 @@ public void testRenameWithBackticksInAgg() {
148153
verifySchemaInOrder(result, schema("avg(`user_age`)", "double"), schema("country", "string"));
149154
verifyDataRows(result, rows(22.5, "Canada"), rows(50.0, "USA"));
150155
}
156+
157+
private void verifyErrorMessage(String actual, String expected) {
158+
String[] actualList = actual.split("input fields are:");
159+
String[] expectedList = expected.split("input fields are:");
160+
assert actualList.length == expectedList.length;
161+
assert actualList.length == 2;
162+
assert actualList[0].equals(expectedList[0]);
163+
assert transferStringToList(actualList[1]).equals(transferStringToList(expectedList[1]));
164+
}
165+
166+
private HashSet<String> transferStringToList(String listString) {
167+
List<String> list =
168+
Arrays.stream(listString.strip().substring(1, listString.length() - 1).split(",")).collect(Collectors.toList());
169+
return new HashSet<>(list.stream().map(s -> s.strip()).collect(Collectors.toList()));
170+
}
151171
}

0 commit comments

Comments
 (0)