Skip to content

Commit 6cc5a69

Browse files
author
Selina Song
committed
Sort collation implemented, added ExplainIT
Signed-off-by: Selina Song <[email protected]>
1 parent bd75b7c commit 6cc5a69

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -219,33 +219,18 @@ public void testExplainWithReverse() throws IOException {
219219

220220
@Test
221221
public void testExplainWithReversePushdown() throws IOException {
222-
// Test with a sort operation that should use the reverse pushdown optimization
223-
String result =
224-
executeWithReplace(
225-
"explain source=opensearch-sql_test_index_account | sort - age | reverse");
226-
227-
// Verify that the plan contains a LogicalSort with ascending direction (reversed from DESC)
228-
assertTrue(result.contains("LogicalSort"));
229-
assertTrue(result.contains("dir0=[ASC]"));
230-
231-
// Verify that ROW_NUMBER is NOT used (since we're using the collation-based optimization)
232-
assertFalse(result.contains("ROW_NUMBER()"));
222+
String query = "source=opensearch-sql_test_index_account | sort - age | reverse";
223+
var result = explainQueryToString(query);
224+
String expected = loadFromFile("expectedOutput/calcite/explain_reverse_pushdown_single.json");
225+
assertJsonEqualsIgnoreId(expected, result);
233226
}
234227

235228
@Test
236229
public void testExplainWithReversePushdownMultipleFields() throws IOException {
237-
// Test with multiple sort fields that should use the reverse pushdown optimization
238-
String result =
239-
executeWithReplace(
240-
"explain source=opensearch-sql_test_index_account | sort - age, + firstname | reverse");
241-
242-
// Verify that the plan contains a LogicalSort with reversed directions
243-
assertTrue(result.contains("LogicalSort"));
244-
assertTrue(result.contains("dir0=[ASC]")); // age was DESC, now ASC
245-
assertTrue(result.contains("dir1=[DESC]")); // firstname was ASC, now DESC
246-
247-
// Verify that ROW_NUMBER is NOT used (since we're using the collation-based optimization)
248-
assertFalse(result.contains("ROW_NUMBER()"));
230+
String query = "source=opensearch-sql_test_index_account | sort - age, + firstname | reverse";
231+
var result = explainQueryToString(query);
232+
String expected = loadFromFile("expectedOutput/calcite/explain_reverse_pushdown_multiple.json");
233+
assertJsonEqualsIgnoreId(expected, result);
249234
}
250235

251236
@Test
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalSystemLimit(sort0=[$8], sort1=[$1], dir0=[ASC], dir1=[DESC], fetch=[10000], type=[QUERY_SIZE_LIMIT])\n LogicalProject(account_number=[$0], firstname=[$1], address=[$2], balance=[$3], gender=[$4], city=[$5], employer=[$6], state=[$7], age=[$8], email=[$9], lastname=[$10])\n LogicalSort(sort0=[$8], sort1=[$1], dir0=[ASC], dir1=[DESC])\n LogicalSort(sort0=[$8], sort1=[$1], dir0=[DESC-nulls-last], dir1=[ASC-nulls-first])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]], PushDownContext=[[PROJECT->[account_number, firstname, address, balance, gender, city, employer, state, age, email, lastname], SORT->[{\n \"age\" : {\n \"order\" : \"asc\",\n \"missing\" : \"_last\"\n }\n}, {\n \"firstname.keyword\" : {\n \"order\" : \"desc\",\n \"missing\" : \"_first\"\n }\n}], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"size\":10000,\"timeout\":\"1m\",\"_source\":{\"includes\":[\"account_number\",\"firstname\",\"address\",\"balance\",\"gender\",\"city\",\"employer\",\"state\",\"age\",\"email\",\"lastname\"],\"excludes\":[]},\"sort\":[{\"age\":{\"order\":\"asc\",\"missing\":\"_last\"}},{\"firstname.keyword\":{\"order\":\"desc\",\"missing\":\"_first\"}}]}, requestedTotalSize=10000, pageSize=null, startFrom=0)])\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": "LogicalSystemLimit(sort0=[$8], dir0=[ASC], fetch=[10000], type=[QUERY_SIZE_LIMIT])\n LogicalProject(account_number=[$0], firstname=[$1], address=[$2], balance=[$3], gender=[$4], city=[$5], employer=[$6], state=[$7], age=[$8], email=[$9], lastname=[$10])\n LogicalSort(sort0=[$8], dir0=[ASC])\n LogicalSort(sort0=[$8], dir0=[DESC-nulls-last])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]], PushDownContext=[[PROJECT->[account_number, firstname, address, balance, gender, city, employer, state, age, email, lastname], SORT->[{\n \"age\" : {\n \"order\" : \"asc\",\n \"missing\" : \"_last\"\n }\n}], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"size\":10000,\"timeout\":\"1m\",\"_source\":{\"includes\":[\"account_number\",\"firstname\",\"address\",\"balance\",\"gender\",\"city\",\"employer\",\"state\",\"age\",\"email\",\"lastname\"],\"excludes\":[]},\"sort\":[{\"age\":{\"order\":\"asc\",\"missing\":\"_last\"}}]}, requestedTotalSize=10000, pageSize=null, startFrom=0)])\n"
5+
}
6+
}

0 commit comments

Comments
 (0)