Skip to content

Commit 4ba852d

Browse files
committed
Move expected explain strings to files to circurmvent issues related to comparison involves windows new lines
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 03612b3 commit 4ba852d

10 files changed

Lines changed: 50 additions & 64 deletions

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

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,12 @@ public void init() throws Exception {
3333
}
3434

3535
@Test
36-
public void testExplainCommand() throws IOException {
36+
public void testExplainCommand() throws Exception {
3737
var result = executeQuery("explain source=test | where age = 20 | fields name, age");
3838
String expected =
3939
isPushdownEnabled()
40-
? """
41-
{
42-
"calcite": {
43-
"physical": "CalciteEnumerableIndexScan(table=[[OpenSearch, test]], PushDownContext=[[PROJECT->[name, age], FILTER->=($1, 20)], OpenSearchRequestBuilder(sourceBuilder={\\"from\\":0,\\"timeout\\":\\"1m\\",\\"query\\":{\\"term\\":{\\"age\\":{\\"value\\":20,\\"boost\\":1.0}}},\\"_source\\":{\\"includes\\":[\\"name\\",\\"age\\"],\\"excludes\\":[]},\\"sort\\":[{\\"_doc\\":{\\"order\\":\\"asc\\"}}]}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])\\n",
44-
"logical": "LogicalProject(name=[$0], age=[$1])\\n LogicalFilter(condition=[=($1, 20)])\\n CalciteLogicalIndexScan(table=[[OpenSearch, test]])\\n"
45-
}
46-
}
47-
"""
48-
: """
49-
{
50-
"calcite": {
51-
"logical": "LogicalProject(name=[$0], age=[$1])\\n LogicalFilter(condition=[=($1, 20)])\\n CalciteLogicalIndexScan(table=[[OpenSearch, test]])\\n",
52-
"physical": "EnumerableCalc(expr#0..7=[{inputs}], expr#8=[20], expr#9=[=($t1,\
53-
$t8)], proj#0..1=[{exprs}], $condition=[$t9])\\n CalciteEnumerableIndexScan(table=[[OpenSearch, test]])\\n"
54-
}
55-
}""";
40+
? loadFromFile("expectedOutput/calcite/explain_filter_w_pushdown.json")
41+
: loadFromFile("expectedOutput/calcite/explain_filter_wo_pushdown.json");
5642

5743
assertJsonEquals(expected, result.toString());
5844
}
@@ -73,26 +59,17 @@ public void testExplainCommandCost() throws IOException {
7359
var result = executeQuery("explain cost source=test | where age = 20 | fields name, age");
7460
String expected =
7561
isPushdownEnabled()
76-
? "\"CalciteEnumerableIndexScan(table=[[OpenSearch, test]],"
77-
+ " PushDownContext=[[PROJECT->[name, age], FILTER->=($1, 20)],"
78-
+ " OpenSearchRequestBuilder(sourceBuilder={\\\"from\\\":0,\\\"timeout\\\":\\\"1m\\\",\\\"query\\\":{\\\"term\\\":{\\\"age\\\":{\\\"value\\\":20,\\\"boost\\\":1.0}}},\\\"_source\\\":{\\\"includes\\\":[\\\"name\\\",\\\"age\\\"],\\\"excludes\\\":[]},\\\"sort\\\":[{\\\"_doc\\\":{\\\"order\\\":\\\"asc\\\"}}]},"
79-
+ " requestedTotalSize=2147483647, pageSize=null, startFrom=0)]): rowcount ="
80-
+ " 1215.0, cumulative cost = {1215.0 rows, 1216.0 cpu, 0.0 io}"
81-
: "CalciteEnumerableIndexScan(table=[[OpenSearch, test]]): rowcount = 10000.0,"
82-
+ " cumulative cost = {10000.0 rows, 10001.0 cpu, 0.0 io}";
83-
assertTrue("Got:\n" + result.toString(), result.toString().contains(expected));
62+
? loadFromFile("expectedOutput/calcite/explain_filter_cost_w_pushdown.txt")
63+
: loadFromFile("expectedOutput/calcite/explain_filter_cost_wo_pushdown.txt");
64+
assertTrue(
65+
String.format("Got: %s\n, expected: %s", result, expected),
66+
result.toString().contains(expected));
8467
}
8568

8669
@Test
8770
public void testExplainCommandSimple() throws IOException {
8871
var result = executeQuery("explain simple source=test | where age = 20 | fields name, age");
89-
assertJsonEquals(
90-
"{\n"
91-
+ " \"calcite\": {\n"
92-
+ " \"logical\": \"LogicalProject\\n LogicalFilter\\n CalciteLogicalIndexScan\\n"
93-
+ "\"\n"
94-
+ " }\n"
95-
+ "}",
96-
result.toString());
72+
String expected = loadFromFile("expectedOutput/calcite/explain_filter_simple.json");
73+
assertJsonEquals(expected, result.toString());
9774
}
9875
}

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
import static org.opensearch.sql.util.MatcherUtils.verifySchemaInOrder;
1414

1515
import com.google.common.collect.ImmutableMap;
16-
import com.google.common.io.Resources;
1716
import java.io.IOException;
18-
import java.net.URI;
19-
import java.nio.file.Files;
20-
import java.nio.file.Paths;
2117
import java.util.List;
2218
import java.util.Map;
2319
import org.json.JSONObject;
@@ -68,15 +64,6 @@ public List<?> getSettings() {
6864
};
6965
}
7066

71-
String loadFromFile(String filename) {
72-
try {
73-
URI uri = Resources.getResource(filename).toURI();
74-
return new String(Files.readAllBytes(Paths.get(uri)));
75-
} catch (Exception e) {
76-
throw new RuntimeException(e);
77-
}
78-
}
79-
8067
@Test
8168
public void testQ1() {
8269
String ppl = loadFromFile("tpch/queries/q1.ppl");

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
import static org.hamcrest.Matchers.containsString;
99
import static org.opensearch.sql.util.MatcherUtils.assertJsonEqualsIgnoreId;
1010

11-
import com.google.common.io.Resources;
1211
import java.io.IOException;
13-
import java.net.URI;
14-
import java.nio.file.Files;
15-
import java.nio.file.Paths;
1612
import org.junit.jupiter.api.Test;
1713
import org.opensearch.client.ResponseException;
1814
import org.opensearch.sql.legacy.TestUtils;
@@ -253,11 +249,6 @@ public void testTrendlineWithSortPushDownExplain() throws Exception {
253249
+ "| fields ageTrend"));
254250
}
255251

256-
String loadFromFile(String filename) throws Exception {
257-
URI uri = Resources.getResource(filename).toURI();
258-
return new String(Files.readAllBytes(Paths.get(uri)));
259-
}
260-
261252
@Test
262253
public void testExplainModeUnsupportedInV2() throws IOException {
263254
try {

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import static org.opensearch.sql.plugin.rest.RestPPLQueryAction.EXPLAIN_API_ENDPOINT;
1010
import static org.opensearch.sql.plugin.rest.RestPPLQueryAction.QUERY_API_ENDPOINT;
1111

12+
import com.google.common.io.Resources;
1213
import java.io.IOException;
14+
import java.net.URI;
15+
import java.nio.file.Files;
16+
import java.nio.file.Paths;
1317
import java.util.Locale;
1418
import org.apache.logging.log4j.LogManager;
1519
import org.apache.logging.log4j.Logger;
@@ -249,4 +253,21 @@ public void updatePushdownSettings() throws IOException {
249253
String.valueOf(GlobalPushdownConfig.enabled)));
250254
}
251255
}
256+
257+
// Utility methods
258+
259+
/**
260+
* Load a file from the resources directory and return its content as a String.
261+
*
262+
* @param filename the name of the file to load
263+
* @return the content of the file as a String
264+
*/
265+
protected static String loadFromFile(String filename) {
266+
try {
267+
URI uri = Resources.getResource(filename).toURI();
268+
return new String(Files.readAllBytes(Paths.get(uri)));
269+
} catch (Exception e) {
270+
throw new RuntimeException(e);
271+
}
272+
}
252273
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
import static org.opensearch.sql.util.MatcherUtils.verifySchema;
1717

1818
import com.google.common.collect.ImmutableMap;
19-
import com.google.common.io.Resources;
2019
import java.io.IOException;
21-
import java.net.URI;
22-
import java.nio.file.Files;
23-
import java.nio.file.Paths;
2420
import java.time.LocalDateTime;
2521
import java.time.format.DateTimeFormatter;
2622
import java.util.Date;
@@ -317,9 +313,4 @@ public void testQueryOnDisabledDataSource() throws IOException {
317313
Response deleteResponse = client().performRequest(deleteRequest);
318314
Assert.assertEquals(204, deleteResponse.getStatusLine().getStatusCode());
319315
}
320-
321-
String loadFromFile(String filename) throws Exception {
322-
URI uri = Resources.getResource(filename).toURI();
323-
return new String(Files.readAllBytes(Paths.get(uri)));
324-
}
325316
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CalciteEnumerableIndexScan(table=[[OpenSearch, test]], PushDownContext=[[PROJECT->[name, age], FILTER->=($1, 20)], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"timeout\":\"1m\",\"query\":{\"term\":{\"age\":{\"value\":20,\"boost\":1.0}}},\"_source\":{\"includes\":[\"name\",\"age\"],\"excludes\":[]},\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)]): rowcount = 1215.0, cumulative cost = {1215.0 rows, 1216.0 cpu, 0.0 io}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CalciteEnumerableIndexScan(table=[[OpenSearch, test]]): rowcount = 10000.0, cumulative cost = {10000.0 rows, 10001.0 cpu, 0.0 io}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"calcite" : {
3+
"logical" : "LogicalProject\n LogicalFilter\n CalciteLogicalIndexScan\n"
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite" : {
3+
"physical" : "CalciteEnumerableIndexScan(table=[[OpenSearch, test]], PushDownContext=[[PROJECT->[name, age], FILTER->=($1, 20)], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"timeout\":\"1m\",\"query\":{\"term\":{\"age\":{\"value\":20,\"boost\":1.0}}},\"_source\":{\"includes\":[\"name\",\"age\"],\"excludes\":[]},\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])\n",
4+
"logical" : "LogicalProject(name=[$0], age=[$1])\n LogicalFilter(condition=[=($1, 20)])\n CalciteLogicalIndexScan(table=[[OpenSearch, test]])\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(name=[$0], age=[$1])\n LogicalFilter(condition=[=($1, 20)])\n CalciteLogicalIndexScan(table=[[OpenSearch, test]])\n",
4+
"physical" : "EnumerableCalc(expr#0..7=[{inputs}], expr#8=[20], expr#9=[=($t1, $t8)], proj#0..1=[{exprs}], $condition=[$t9])\n CalciteEnumerableIndexScan(table=[[OpenSearch, test]])\n"
5+
}
6+
}

0 commit comments

Comments
 (0)