Skip to content

Commit c6ad7db

Browse files
committed
Use executeWithReplace for explain command variants
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 7a0c629 commit c6ad7db

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalcitePPLExplainIT.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void init() throws Exception {
3434

3535
@Test
3636
public void testExplainCommand() throws IOException {
37-
var result = explainQueryToString("explain source=test | where age = 20 | fields name, age");
37+
var result = explainQueryToString("source=test | where age = 20 | fields name, age");
3838
String expected =
3939
isPushdownEnabled()
4040
? loadFromFile("expectedOutput/calcite/explain_filter_w_pushdown.json")
@@ -46,7 +46,7 @@ public void testExplainCommand() throws IOException {
4646
@Test
4747
public void testExplainCommandExtended() throws IOException {
4848
var result =
49-
explainQueryToString("explain extended source=test | where age = 20 | fields name, age");
49+
executeWithReplace("explain extended source=test | where age = 20 | fields name, age");
5050
assertTrue(
5151
result.contains(
5252
"public org.apache.calcite.linq4j.Enumerable bind(final"
@@ -55,8 +55,7 @@ public void testExplainCommandExtended() throws IOException {
5555

5656
@Test
5757
public void testExplainCommandCost() throws IOException {
58-
var result =
59-
explainQueryToString("explain cost source=test | where age = 20 | fields name, age");
58+
var result = executeWithReplace("explain cost source=test | where age = 20 | fields name, age");
6059
String expected =
6160
isPushdownEnabled()
6261
? loadFromFile("expectedOutput/calcite/explain_filter_cost_w_pushdown.txt")
@@ -68,8 +67,21 @@ public void testExplainCommandCost() throws IOException {
6867
@Test
6968
public void testExplainCommandSimple() throws IOException {
7069
var result =
71-
explainQueryToString("explain simple source=test | where age = 20 | fields name, age");
70+
executeWithReplace("explain simple source=test | where age = 20 | fields name, age");
7271
String expected = loadFromFile("expectedOutput/calcite/explain_filter_simple.json");
7372
assertJsonEquals(expected, result);
7473
}
74+
75+
/**
76+
* Executes the PPL query and returns the result as a string with windows-style line breaks
77+
* replaced with Unix-style ones.
78+
*
79+
* @param ppl the PPL query to execute
80+
* @return the result of the query as a string with line breaks replaced
81+
* @throws IOException if an error occurs during query execution
82+
*/
83+
private String executeWithReplace(String ppl) throws IOException {
84+
var result = executeQueryToString(ppl);
85+
return result.replace("\\r\\n", "\\n");
86+
}
7587
}

0 commit comments

Comments
 (0)