@@ -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}
0 commit comments