Skip to content

Commit 49beb76

Browse files
committed
Migrate CalcitePPLTpchIT to remote test
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent c6ad7db commit 49beb76

1 file changed

Lines changed: 65 additions & 82 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/calcite/tpch/CalcitePPLTpchIT.java

Lines changed: 65 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,26 @@
55

66
package org.opensearch.sql.calcite.tpch;
77

8+
import static org.opensearch.sql.util.MatcherUtils.assertJsonEquals;
89
import static org.opensearch.sql.util.MatcherUtils.closeTo;
910
import static org.opensearch.sql.util.MatcherUtils.rows;
1011
import static org.opensearch.sql.util.MatcherUtils.schema;
1112
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
1213
import static org.opensearch.sql.util.MatcherUtils.verifyNumOfRows;
1314
import static org.opensearch.sql.util.MatcherUtils.verifySchemaInOrder;
1415

15-
import com.google.common.collect.ImmutableMap;
1616
import java.io.IOException;
17-
import java.util.List;
18-
import java.util.Map;
1917
import org.json.JSONObject;
2018
import org.junit.Test;
21-
import org.opensearch.common.unit.TimeValue;
22-
import org.opensearch.sql.calcite.standalone.CalcitePPLIntegTestCase;
23-
import org.opensearch.sql.common.setting.Settings;
19+
import org.opensearch.sql.ppl.PPLIntegTestCase;
2420

25-
public class CalcitePPLTpchIT extends CalcitePPLIntegTestCase {
21+
public class CalcitePPLTpchIT extends PPLIntegTestCase {
2622

2723
@Override
28-
public void init() throws IOException {
24+
public void init() throws Exception {
2925
super.init();
26+
enableCalcite();
27+
disallowCalciteFallback();
3028

3129
loadIndex(Index.TPCH_CUSTOMER);
3230
loadIndex(Index.TPCH_LINEITEM);
@@ -38,35 +36,9 @@ public void init() throws IOException {
3836
loadIndex(Index.TPCH_REGION);
3937
}
4038

41-
@Override
42-
public Settings getSettings() {
43-
return new Settings() {
44-
private final Map<Key, Object> defaultSettings =
45-
new ImmutableMap.Builder<Key, Object>()
46-
.put(Key.QUERY_SIZE_LIMIT, 10000)
47-
.put(Key.SQL_CURSOR_KEEP_ALIVE, TimeValue.timeValueMinutes(1))
48-
.put(Key.FIELD_TYPE_TOLERANCE, true)
49-
.put(Key.CALCITE_ENGINE_ENABLED, true)
50-
.put(Key.CALCITE_FALLBACK_ALLOWED, false)
51-
.put(Key.CALCITE_PUSHDOWN_ENABLED, true)
52-
.put(Key.CALCITE_PUSHDOWN_ROWCOUNT_ESTIMATION_FACTOR, 0.9)
53-
.build();
54-
55-
@Override
56-
public <T> T getSettingValue(Key key) {
57-
return (T) defaultSettings.get(key);
58-
}
59-
60-
@Override
61-
public List<?> getSettings() {
62-
return (List<?>) defaultSettings;
63-
}
64-
};
65-
}
66-
6739
@Test
68-
public void testQ1() {
69-
String ppl = loadFromFile("tpch/queries/q1.ppl");
40+
public void testQ1() throws IOException {
41+
String ppl = sanitize(loadFromFile("tpch/queries/q1.ppl"));
7042
JSONObject actual = executeQuery(ppl);
7143
verifySchemaInOrder(
7244
actual,
@@ -129,8 +101,8 @@ public void testQ1() {
129101
}
130102

131103
@Test
132-
public void testQ2() {
133-
String ppl = loadFromFile("tpch/queries/q2.ppl");
104+
public void testQ2() throws IOException {
105+
String ppl = sanitize(loadFromFile("tpch/queries/q2.ppl"));
134106
JSONObject actual = executeQuery(ppl);
135107
verifySchemaInOrder(
136108
actual,
@@ -146,8 +118,8 @@ public void testQ2() {
146118
}
147119

148120
@Test
149-
public void testQ3() {
150-
String ppl = loadFromFile("tpch/queries/q3.ppl");
121+
public void testQ3() throws IOException {
122+
String ppl = sanitize(loadFromFile("tpch/queries/q3.ppl"));
151123
JSONObject actual = executeQuery(ppl);
152124
verifySchemaInOrder(
153125
actual,
@@ -168,8 +140,8 @@ public void testQ3() {
168140
}
169141

170142
@Test
171-
public void testQ4() {
172-
String ppl = loadFromFile("tpch/queries/q4.ppl");
143+
public void testQ4() throws IOException {
144+
String ppl = sanitize(loadFromFile("tpch/queries/q4.ppl"));
173145
JSONObject actual = executeQuery(ppl);
174146
verifySchemaInOrder(
175147
actual, schema("o_orderpriority", "string"), schema("order_count", "bigint"));
@@ -183,23 +155,23 @@ public void testQ4() {
183155
}
184156

185157
@Test
186-
public void testQ5() {
187-
String ppl = loadFromFile("tpch/queries/q5.ppl");
158+
public void testQ5() throws IOException {
159+
String ppl = sanitize(loadFromFile("tpch/queries/q5.ppl"));
188160
JSONObject actual = executeQuery(ppl);
189161
verifySchemaInOrder(actual, schema("n_name", "string"), schema("revenue", "double"));
190162
verifyNumOfRows(actual, 0);
191163
}
192164

193165
@Test
194-
public void testQ6() {
195-
String ppl = loadFromFile("tpch/queries/q6.ppl");
166+
public void testQ6() throws IOException {
167+
String ppl = sanitize(loadFromFile("tpch/queries/q6.ppl"));
196168
JSONObject actual = executeQuery(ppl);
197169
verifySchemaInOrder(actual, schema("revenue", "double"));
198170
verifyDataRows(actual, rows(77949.9186));
199171
}
200172

201-
public void testQ7() {
202-
String ppl = loadFromFile("tpch/queries/q7.ppl");
173+
public void testQ7() throws IOException {
174+
String ppl = sanitize(loadFromFile("tpch/queries/q7.ppl"));
203175
JSONObject actual = executeQuery(ppl);
204176
verifySchemaInOrder(
205177
actual,
@@ -210,16 +182,16 @@ public void testQ7() {
210182
verifyNumOfRows(actual, 0);
211183
}
212184

213-
public void testQ8() {
214-
String ppl = loadFromFile("tpch/queries/q8.ppl");
185+
public void testQ8() throws IOException {
186+
String ppl = sanitize(loadFromFile("tpch/queries/q8.ppl"));
215187
JSONObject actual = executeQuery(ppl);
216188
verifySchemaInOrder(actual, schema("o_year", "int"), schema("mkt_share", "double"));
217189
verifyDataRows(actual, rows(1995, 0.0), rows(1996, 0.0));
218190
}
219191

220192
@Test
221-
public void testQ9() {
222-
String ppl = loadFromFile("tpch/queries/q9.ppl");
193+
public void testQ9() throws IOException {
194+
String ppl = sanitize(loadFromFile("tpch/queries/q9.ppl"));
223195
JSONObject actual = executeQuery(ppl);
224196
verifySchemaInOrder(
225197
actual,
@@ -230,8 +202,8 @@ public void testQ9() {
230202
}
231203

232204
@Test
233-
public void testQ10() {
234-
String ppl = loadFromFile("tpch/queries/q10.ppl");
205+
public void testQ10() throws IOException {
206+
String ppl = sanitize(loadFromFile("tpch/queries/q10.ppl"));
235207
JSONObject actual = executeQuery(ppl);
236208
verifySchemaInOrder(
237209
actual,
@@ -259,16 +231,16 @@ public void testQ10() {
259231
}
260232

261233
@Test
262-
public void testQ11() {
263-
String ppl = loadFromFile("tpch/queries/q11.ppl");
234+
public void testQ11() throws IOException {
235+
String ppl = sanitize(loadFromFile("tpch/queries/q11.ppl"));
264236
JSONObject actual = executeQuery(ppl);
265237
verifySchemaInOrder(actual, schema("ps_partkey", "bigint"), schema("value", "double"));
266238
verifyNumOfRows(actual, 0);
267239
}
268240

269241
@Test
270-
public void testQ12() {
271-
String ppl = loadFromFile("tpch/queries/q12.ppl");
242+
public void testQ12() throws IOException {
243+
String ppl = sanitize(loadFromFile("tpch/queries/q12.ppl"));
272244
JSONObject actual = executeQuery(ppl);
273245
verifySchemaInOrder(
274246
actual,
@@ -279,8 +251,8 @@ public void testQ12() {
279251
}
280252

281253
@Test
282-
public void testQ13() {
283-
String ppl = loadFromFile("tpch/queries/q13.ppl");
254+
public void testQ13() throws IOException {
255+
String ppl = sanitize(loadFromFile("tpch/queries/q13.ppl"));
284256
JSONObject actual = executeQuery(ppl);
285257
verifySchemaInOrder(actual, schema("c_count", "bigint"), schema("custdist", "bigint"));
286258
verifyDataRows(
@@ -315,16 +287,16 @@ public void testQ13() {
315287
}
316288

317289
@Test
318-
public void testQ14() {
319-
String ppl = loadFromFile("tpch/queries/q14.ppl");
290+
public void testQ14() throws IOException {
291+
String ppl = sanitize(loadFromFile("tpch/queries/q14.ppl"));
320292
JSONObject actual = executeQuery(ppl);
321293
verifySchemaInOrder(actual, schema("promo_revenue", "double"));
322294
verifyDataRows(actual, closeTo(15.230212611597254));
323295
}
324296

325297
@Test
326-
public void testQ15() {
327-
String ppl = loadFromFile("tpch/queries/q15.ppl");
298+
public void testQ15() throws IOException {
299+
String ppl = sanitize(loadFromFile("tpch/queries/q15.ppl"));
328300
JSONObject actual = executeQuery(ppl);
329301
verifySchemaInOrder(
330302
actual,
@@ -339,8 +311,8 @@ public void testQ15() {
339311
}
340312

341313
@Test
342-
public void testQ16() {
343-
String ppl = loadFromFile("tpch/queries/q16.ppl");
314+
public void testQ16() throws IOException {
315+
String ppl = sanitize(loadFromFile("tpch/queries/q16.ppl"));
344316
JSONObject actual = executeQuery(ppl);
345317
verifySchemaInOrder(
346318
actual,
@@ -387,10 +359,10 @@ public void testQ16() {
387359
}
388360

389361
@Test
390-
public void testQ17() {
391-
String ppl = loadFromFile("tpch/queries/q17.ppl");
392-
String actual = execute(ppl);
393-
assertEquals(
362+
public void testQ17() throws IOException {
363+
String ppl = sanitize(loadFromFile("tpch/queries/q17.ppl"));
364+
String actual = executeQuery(ppl).toString();
365+
assertJsonEquals(
394366
"{\n"
395367
+ " \"schema\": [\n"
396368
+ " {\n"
@@ -410,8 +382,8 @@ public void testQ17() {
410382
}
411383

412384
@Test
413-
public void testQ18() {
414-
String ppl = loadFromFile("tpch/queries/q18.ppl");
385+
public void testQ18() throws IOException {
386+
String ppl = sanitize(loadFromFile("tpch/queries/q18.ppl"));
415387
JSONObject actual = executeQuery(ppl);
416388
verifySchemaInOrder(
417389
actual,
@@ -425,10 +397,10 @@ public void testQ18() {
425397
}
426398

427399
@Test
428-
public void testQ19() {
429-
String ppl = loadFromFile("tpch/queries/q19.ppl");
430-
String actual = execute(ppl);
431-
assertEquals(
400+
public void testQ19() throws IOException {
401+
String ppl = sanitize(loadFromFile("tpch/queries/q19.ppl"));
402+
String actual = executeQuery(ppl).toString();
403+
assertJsonEquals(
432404
"{\n"
433405
+ " \"schema\": [\n"
434406
+ " {\n"
@@ -448,24 +420,24 @@ public void testQ19() {
448420
}
449421

450422
@Test
451-
public void testQ20() {
452-
String ppl = loadFromFile("tpch/queries/q20.ppl");
423+
public void testQ20() throws IOException {
424+
String ppl = sanitize(loadFromFile("tpch/queries/q20.ppl"));
453425
JSONObject actual = executeQuery(ppl);
454426
verifySchemaInOrder(actual, schema("s_name", "string"), schema("s_address", "string"));
455427
verifyNumOfRows(actual, 0);
456428
}
457429

458430
@Test
459-
public void testQ21() {
460-
String ppl = loadFromFile("tpch/queries/q21.ppl");
431+
public void testQ21() throws IOException {
432+
String ppl = sanitize(loadFromFile("tpch/queries/q21.ppl"));
461433
JSONObject actual = executeQuery(ppl);
462434
verifySchemaInOrder(actual, schema("s_name", "string"), schema("numwait", "bigint"));
463435
verifyNumOfRows(actual, 0);
464436
}
465437

466438
@Test
467-
public void testQ22() {
468-
String ppl = loadFromFile("tpch/queries/q22.ppl");
439+
public void testQ22() throws IOException {
440+
String ppl = sanitize(loadFromFile("tpch/queries/q22.ppl"));
469441
JSONObject actual = executeQuery(ppl);
470442
verifySchemaInOrder(
471443
actual,
@@ -482,4 +454,15 @@ public void testQ22() {
482454
rows("30", 1, 7638.57),
483455
rows("31", 1, 9331.13));
484456
}
457+
458+
/**
459+
* Sanitizes the PPL query by removing block comments and replacing new lines with spaces.
460+
*
461+
* @param ppl the PPL query string
462+
* @return the sanitized PPL query string
463+
*/
464+
private static String sanitize(String ppl) {
465+
String withoutComments = ppl.replaceAll("(?s)/\\*.*?\\*/", "");
466+
return withoutComments.replaceAll("\\n", " ").trim();
467+
}
485468
}

0 commit comments

Comments
 (0)