Skip to content

Commit e13dc72

Browse files
committed
Test explaining sort | stats avg
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 8167f97 commit e13dc72

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ public void testMultiSortPushDownExplain() throws IOException {
125125
+ "| fields account_number, firstname, address, balance, gender"));
126126
}
127127

128+
@Test
129+
public void testSortThenAggregatePushDownExplain() throws IOException {
130+
// TODO: Remove pushed-down sort in DSL in expectedOutput/ppl/explain_sort_then_agg_push.json
131+
// existing collations should be eliminated when pushing down aggregations
132+
String expected =
133+
isCalciteEnabled()
134+
? loadFromFile("expectedOutput/calcite/explain_sort_then_agg_push.json")
135+
: loadFromFile("expectedOutput/ppl/explain_sort_then_agg_push.json");
136+
137+
assertJsonEqualsIgnoreId(
138+
expected,
139+
explainQueryToString(
140+
"source=opensearch-sql_test_index_account"
141+
+ "| sort balance, age "
142+
+ "| stats avg(balance) by state"));
143+
}
144+
128145
@Test
129146
public void testLimitPushDownExplain() throws IOException {
130147
String expected =
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(avg(balance)=[$1], state=[$0])\n LogicalAggregate(group=[{0}], avg(balance)=[AVG($1)])\n LogicalProject(state=[$7], balance=[$3])\n LogicalSort(sort0=[$3], sort1=[$8], dir0=[ASC], dir1=[ASC])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableCalc(expr#0..1=[{inputs}], avg(balance)=[$t1], state=[$t0])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]], PushDownContext=[[PROJECT->[balance, state, age], AGGREGATION->rel#1428:LogicalAggregate.NONE.[](input=RelSubset#1418,group={1},avg(balance)=AVG($0))], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"size\":0,\"timeout\":\"1m\",\"_source\":{\"includes\":[\"balance\",\"state\",\"age\"],\"excludes\":[]},\"aggregations\":{\"composite_buckets\":{\"composite\":{\"size\":1000,\"sources\":[{\"state\":{\"terms\":{\"field\":\"state.keyword\",\"missing_bucket\":true,\"missing_order\":\"first\",\"order\":\"asc\"}}}]},\"aggregations\":{\"avg(balance)\":{\"avg\":{\"field\":\"balance\"}}}}}}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])\n"
5+
}
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"root": {
3+
"name": "ProjectOperator",
4+
"description": {
5+
"fields": "[avg(balance), state]"
6+
},
7+
"children": [
8+
{
9+
"name": "OpenSearchIndexScan",
10+
"description": {
11+
"request": "OpenSearchQueryRequest(indexName=opensearch-sql_test_index_account, sourceBuilder={\"from\":0,\"size\":0,\"timeout\":\"1m\",\"sort\":[{\"balance\":{\"order\":\"asc\",\"missing\":\"_first\"}},{\"age\":{\"order\":\"asc\",\"missing\":\"_first\"}}],\"aggregations\":{\"composite_buckets\":{\"composite\":{\"size\":1000,\"sources\":[{\"state\":{\"terms\":{\"field\":\"state.keyword\",\"missing_bucket\":true,\"missing_order\":\"first\",\"order\":\"asc\"}}}]},\"aggregations\":{\"avg(balance)\":{\"avg\":{\"field\":\"balance\"}}}}}}, needClean=true, searchDone=false, pitId=null, cursorKeepAlive=null, searchAfter=null, searchResponse=null)"
12+
},
13+
"children": []
14+
}
15+
]
16+
}
17+
}

0 commit comments

Comments
 (0)