Skip to content

Commit 47a4135

Browse files
committed
Add explain ITs with Calcite wihtout pushdown
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 918c153 commit 47a4135

20 files changed

Lines changed: 142 additions & 75 deletions

integ-test/src/test/java/org/opensearch/sql/calcite/pushdown/CalciteNoPushdownIT.java renamed to integ-test/src/test/java/org/opensearch/sql/calcite/CalciteNoPushdownIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package org.opensearch.sql.calcite.pushdown;
6+
package org.opensearch.sql.calcite;
77

88
import org.junit.AfterClass;
99
import org.junit.BeforeClass;
@@ -30,8 +30,7 @@
3030
CalciteDedupCommandIT.class,
3131
CalciteDescribeCommandIT.class,
3232
CalciteExpandCommandIT.class,
33-
// TODO: Add expected plans for CalciteExplainIT without pushdown
34-
// CalciteExplainIT.class,
33+
CalciteExplainIT.class,
3534
CalciteFieldsCommandIT.class,
3635
CalciteFillNullCommandIT.class,
3736
CalciteFlattenCommandIT.class,

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

Lines changed: 32 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ public void init() throws Exception {
2323

2424
@Test
2525
public void testExplain() throws IOException {
26-
String expected =
27-
isCalciteEnabled()
28-
? loadFromFile("expectedOutput/calcite/explain_output.json")
29-
: loadFromFile("expectedOutput/ppl/explain_output.json");
26+
String expected = loadExpectedPlan("explain_output.json");
3027
assertJsonEqualsIgnoreId(
3128
expected,
3229
explainQueryToString(
@@ -42,10 +39,7 @@ public void testExplain() throws IOException {
4239

4340
@Test
4441
public void testFilterPushDownExplain() throws IOException {
45-
String expected =
46-
isCalciteEnabled()
47-
? loadFromFile("expectedOutput/calcite/explain_filter_push.json")
48-
: loadFromFile("expectedOutput/ppl/explain_filter_push.json");
42+
String expected = loadExpectedPlan("explain_filter_push.json");
4943

5044
assertJsonEqualsIgnoreId(
5145
expected,
@@ -59,10 +53,7 @@ public void testFilterPushDownExplain() throws IOException {
5953

6054
@Test
6155
public void testFilterAndAggPushDownExplain() throws IOException {
62-
String expected =
63-
isCalciteEnabled()
64-
? loadFromFile("expectedOutput/calcite/explain_filter_agg_push.json")
65-
: loadFromFile("expectedOutput/ppl/explain_filter_agg_push.json");
56+
String expected = loadExpectedPlan("explain_filter_agg_push.json");
6657

6758
assertJsonEqualsIgnoreId(
6859
expected,
@@ -75,10 +66,7 @@ public void testFilterAndAggPushDownExplain() throws IOException {
7566
@Test
7667
public void testSortPushDownExplain() throws IOException {
7768
// TODO fix after https://github.com/opensearch-project/sql/issues/3380
78-
String expected =
79-
isCalciteEnabled()
80-
? loadFromFile("expectedOutput/calcite/explain_sort_push.json")
81-
: loadFromFile("expectedOutput/ppl/explain_sort_push.json");
69+
String expected = loadExpectedPlan("explain_sort_push.json");
8270

8371
assertJsonEqualsIgnoreId(
8472
expected,
@@ -91,10 +79,7 @@ public void testSortPushDownExplain() throws IOException {
9179

9280
@Test
9381
public void testLimitPushDownExplain() throws IOException {
94-
String expected =
95-
isCalciteEnabled()
96-
? loadFromFile("expectedOutput/calcite/explain_limit_push.json")
97-
: loadFromFile("expectedOutput/ppl/explain_limit_push.json");
82+
String expected = loadExpectedPlan("explain_limit_push.json");
9883

9984
assertJsonEqualsIgnoreId(
10085
expected,
@@ -107,10 +92,7 @@ public void testLimitPushDownExplain() throws IOException {
10792

10893
@Test
10994
public void testLimitWithFilterPushdownExplain() throws IOException {
110-
String expectedFilterThenLimit =
111-
isCalciteEnabled()
112-
? loadFromFile("expectedOutput/calcite/explain_filter_then_limit_push.json")
113-
: loadFromFile("expectedOutput/ppl/explain_filter_then_limit_push.json");
95+
String expectedFilterThenLimit = loadExpectedPlan("explain_filter_then_limit_push.json");
11496
assertJsonEqualsIgnoreId(
11597
expectedFilterThenLimit,
11698
explainQueryToString(
@@ -121,10 +103,7 @@ public void testLimitWithFilterPushdownExplain() throws IOException {
121103

122104
// The filter in limit-then-filter queries should not be pushed since the current DSL will
123105
// execute it as filter-then-limit
124-
String expectedLimitThenFilter =
125-
isCalciteEnabled()
126-
? loadFromFile("expectedOutput/calcite/explain_limit_then_filter_push.json")
127-
: loadFromFile("expectedOutput/ppl/explain_limit_then_filter_push.json");
106+
String expectedLimitThenFilter = loadExpectedPlan("explain_limit_then_filter_push.json");
128107
assertJsonEqualsIgnoreId(
129108
expectedLimitThenFilter,
130109
explainQueryToString(
@@ -136,10 +115,7 @@ public void testLimitWithFilterPushdownExplain() throws IOException {
136115

137116
@Test
138117
public void testMultipleLimitExplain() throws IOException {
139-
String expected5Then10 =
140-
isCalciteEnabled()
141-
? loadFromFile("expectedOutput/calcite/explain_limit_5_10_push.json")
142-
: loadFromFile("expectedOutput/ppl/explain_limit_5_10_push.json");
118+
String expected5Then10 = loadExpectedPlan("explain_limit_5_10_push.json");
143119
assertJsonEqualsIgnoreId(
144120
expected5Then10,
145121
explainQueryToString(
@@ -148,10 +124,7 @@ public void testMultipleLimitExplain() throws IOException {
148124
+ "| head 10 "
149125
+ "| fields age"));
150126

151-
String expected10Then5 =
152-
isCalciteEnabled()
153-
? loadFromFile("expectedOutput/calcite/explain_limit_10_5_push.json")
154-
: loadFromFile("expectedOutput/ppl/explain_limit_10_5_push.json");
127+
String expected10Then5 = loadExpectedPlan("explain_limit_10_5_push.json");
155128
assertJsonEqualsIgnoreId(
156129
expected10Then5,
157130
explainQueryToString(
@@ -160,10 +133,7 @@ public void testMultipleLimitExplain() throws IOException {
160133
+ "| head 5 "
161134
+ "| fields age"));
162135

163-
String expected10from1then10from2 =
164-
isCalciteEnabled()
165-
? loadFromFile("expectedOutput/calcite/explain_limit_10from1_10from2_push.json")
166-
: loadFromFile("expectedOutput/ppl/explain_limit_10from1_10from2_push.json");
136+
String expected10from1then10from2 = loadExpectedPlan("explain_limit_10from1_10from2_push.json");
167137
assertJsonEqualsIgnoreId(
168138
expected10from1then10from2,
169139
explainQueryToString(
@@ -173,10 +143,7 @@ public void testMultipleLimitExplain() throws IOException {
173143
+ "| fields age"));
174144

175145
// The second limit should not be pushed down for limit-filter-limit queries
176-
String expected10ThenFilterThen5 =
177-
isCalciteEnabled()
178-
? loadFromFile("expectedOutput/calcite/explain_limit_10_filter_5_push.json")
179-
: loadFromFile("expectedOutput/ppl/explain_limit_10_filter_5_push.json");
146+
String expected10ThenFilterThen5 = loadExpectedPlan("explain_limit_10_filter_5_push.json");
180147
assertJsonEqualsIgnoreId(
181148
expected10ThenFilterThen5,
182149
explainQueryToString(
@@ -189,10 +156,7 @@ public void testMultipleLimitExplain() throws IOException {
189156

190157
@Test
191158
public void testLimitWithMultipleOffsetPushdownExplain() throws IOException {
192-
String expected =
193-
isCalciteEnabled()
194-
? loadFromFile("expectedOutput/calcite/explain_limit_offsets_push.json")
195-
: loadFromFile("expectedOutput/ppl/explain_limit_offsets_push.json");
159+
String expected = loadExpectedPlan("explain_limit_offsets_push.json");
196160

197161
assertJsonEqualsIgnoreId(
198162
expected,
@@ -205,10 +169,7 @@ public void testLimitWithMultipleOffsetPushdownExplain() throws IOException {
205169

206170
@Test
207171
public void testFillNullPushDownExplain() throws IOException {
208-
String expected =
209-
isCalciteEnabled()
210-
? loadFromFile("expectedOutput/calcite/explain_fillnull_push.json")
211-
: loadFromFile("expectedOutput/ppl/explain_fillnull_push.json");
172+
String expected = loadExpectedPlan("explain_fillnull_push.json");
212173

213174
assertJsonEqualsIgnoreId(
214175
expected,
@@ -219,10 +180,7 @@ public void testFillNullPushDownExplain() throws IOException {
219180

220181
@Test
221182
public void testTrendlinePushDownExplain() throws IOException {
222-
String expected =
223-
isCalciteEnabled()
224-
? loadFromFile("expectedOutput/calcite/explain_trendline_push.json")
225-
: loadFromFile("expectedOutput/ppl/explain_trendline_push.json");
183+
String expected = loadExpectedPlan("explain_trendline_push.json");
226184

227185
assertJsonEqualsIgnoreId(
228186
expected,
@@ -235,10 +193,7 @@ public void testTrendlinePushDownExplain() throws IOException {
235193

236194
@Test
237195
public void testTrendlineWithSortPushDownExplain() throws IOException {
238-
String expected =
239-
isCalciteEnabled()
240-
? loadFromFile("expectedOutput/calcite/explain_trendline_sort_push.json")
241-
: loadFromFile("expectedOutput/ppl/explain_trendline_sort_push.json");
196+
String expected = loadExpectedPlan("explain_trendline_sort_push.json");
242197

243198
assertJsonEqualsIgnoreId(
244199
expected,
@@ -264,10 +219,7 @@ public void testExplainModeUnsupportedInV2() throws IOException {
264219
@Test
265220
public void testPatternsSimplePatternMethodWithoutAggExplain() throws IOException {
266221
// TODO: Correct calcite expected result once pushdown is supported
267-
String expected =
268-
isCalciteEnabled()
269-
? loadFromFile("expectedOutput/calcite/explain_patterns_simple_pattern.json")
270-
: loadFromFile("expectedOutput/ppl/explain_patterns_simple_pattern.json");
222+
String expected = loadExpectedPlan("explain_patterns_simple_pattern.json");
271223

272224
assertJsonEqualsIgnoreId(
273225
expected,
@@ -277,10 +229,7 @@ public void testPatternsSimplePatternMethodWithoutAggExplain() throws IOExceptio
277229
@Test
278230
public void testPatternsSimplePatternMethodWithAggPushDownExplain() throws IOException {
279231
// TODO: Correct calcite expected result once pushdown is supported
280-
String expected =
281-
isCalciteEnabled()
282-
? loadFromFile("expectedOutput/calcite/explain_patterns_simple_pattern_agg_push.json")
283-
: loadFromFile("expectedOutput/ppl/explain_patterns_simple_pattern_agg_push.json");
232+
String expected = loadExpectedPlan("explain_patterns_simple_pattern_agg_push.json");
284233

285234
assertJsonEqualsIgnoreId(
286235
expected,
@@ -291,15 +240,26 @@ public void testPatternsSimplePatternMethodWithAggPushDownExplain() throws IOExc
291240
@Test
292241
public void testPatternsBrainMethodWithAggPushDownExplain() throws IOException {
293242
// TODO: Correct calcite expected result once pushdown is supported
294-
String expected =
295-
isCalciteEnabled()
296-
? loadFromFile("expectedOutput/calcite/explain_patterns_brain_agg_push.json")
297-
: loadFromFile("expectedOutput/ppl/explain_patterns_brain_agg_push.json");
243+
String expected = loadExpectedPlan("explain_patterns_brain_agg_push.json");
298244

299245
assertJsonEqualsIgnoreId(
300246
expected,
301247
explainQueryToString(
302248
"source=opensearch-sql_test_index_account"
303249
+ "| patterns email method=brain mode=aggregation"));
304250
}
251+
252+
private String loadExpectedPlan(String fileName) throws IOException {
253+
String prefix;
254+
if (isCalciteEnabled()) {
255+
if (isPushdownEnabled()) {
256+
prefix = "expectedOutput/calcite/";
257+
} else {
258+
prefix = "expectedOutput/calcite_no_pushdown/";
259+
}
260+
} else {
261+
prefix = "expectedOutput/ppl/";
262+
}
263+
return loadFromFile(prefix + fileName);
264+
}
305265
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(age=[COALESCE($8, -1)], balance=[COALESCE($3, -1)])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableCalc(expr#0..16=[{inputs}], expr#17=[-1], expr#18=[COALESCE($t8, $t17)], expr#19=[COALESCE($t3, $t17)], age=[$t18], balance=[$t19])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(avg_age=[$2], state=[$0], city=[$1])\n LogicalAggregate(group=[{0, 1}], avg_age=[AVG($2)])\n LogicalProject(state=[$7], city=[$5], age=[$8])\n LogicalFilter(condition=[>($8, 30)])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableCalc(expr#0..3=[{inputs}], expr#4=[0], expr#5=[=($t3, $t4)], expr#6=[null:BIGINT], expr#7=[CASE($t5, $t6, $t2)], expr#8=[CAST($t7):DOUBLE], expr#9=[/($t8, $t3)], avg_age=[$t9], state=[$t1], city=[$t0])\n EnumerableAggregate(group=[{5, 7}], agg#0=[$SUM0($8)], agg#1=[COUNT($8)])\n EnumerableCalc(expr#0..16=[{inputs}], expr#17=[30], expr#18=[>($t8, $t17)], proj#0..16=[{exprs}], $condition=[$t18])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(age=[$8])\n LogicalFilter(condition=[>($3, 10000)])\n LogicalFilter(condition=[<($8, 40)])\n LogicalFilter(condition=[>($8, 30)])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableCalc(expr#0..16=[{inputs}], expr#17=[Sarg[(30..40)]], expr#18=[SEARCH($t8, $t17)], expr#19=[10000], expr#20=[>($t3, $t19)], expr#21=[AND($t18, $t20)], age=[$t8], $condition=[$t21])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(age=[$8])\n LogicalSort(fetch=[5])\n LogicalFilter(condition=[>($8, 30)])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableCalc(expr#0..16=[{inputs}], age=[$t8])\n EnumerableLimit(fetch=[5])\n EnumerableCalc(expr#0..16=[{inputs}], expr#17=[30], expr#18=[>($t8, $t17)], proj#0..16=[{exprs}], $condition=[$t18])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(age=[$8])\n LogicalSort(fetch=[5])\n LogicalSort(fetch=[10])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableCalc(expr#0..16=[{inputs}], age=[$t8])\n EnumerableLimit(fetch=[5])\n EnumerableLimit(fetch=[10])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(age=[$8])\n LogicalSort(fetch=[5])\n LogicalFilter(condition=[>($8, 30)])\n LogicalSort(fetch=[10])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableLimit(fetch=[5])\n EnumerableCalc(expr#0..16=[{inputs}], expr#17=[30], expr#18=[>($t8, $t17)], age=[$t8], $condition=[$t18])\n EnumerableLimit(fetch=[10])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(age=[$8])\n LogicalSort(offset=[2], fetch=[10])\n LogicalSort(offset=[1], fetch=[10])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableCalc(expr#0..16=[{inputs}], age=[$t8])\n EnumerableLimit(offset=[2], fetch=[10])\n EnumerableLimit(offset=[1], fetch=[10])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(age=[$8])\n LogicalSort(fetch=[10])\n LogicalSort(fetch=[5])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableLimit(fetch=[10])\n EnumerableCalc(expr#0..16=[{inputs}], age=[$t8])\n EnumerableLimit(fetch=[5])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n"
5+
}
6+
}

0 commit comments

Comments
 (0)