Skip to content

Commit e5145d1

Browse files
committed
Add a test for accessing nested filter in filter in aggregation
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 0327b3f commit e5145d1

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,4 +2427,14 @@ public void testFilterOnMultipleCascadedNestedFields() throws IOException {
24272427
+ " < 6 and author.books.title = 'The Shining'",
24282428
TEST_INDEX_CASCADED_NESTED)));
24292429
}
2430+
2431+
@Test
2432+
public void testAggFilterOnNestedFields() throws IOException {
2433+
assertYamlEqualsIgnoreId(
2434+
loadExpectedPlan("agg_filter_nested.yaml"),
2435+
explainQueryYaml(
2436+
StringUtils.format(
2437+
"source=%s | stats count(eval(author.name < 'K')) as george_and_jk",
2438+
TEST_INDEX_CASCADED_NESTED)));
2439+
}
24302440
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020
import org.json.JSONObject;
2121
import org.junit.Test;
22+
import org.opensearch.sql.common.utils.StringUtils;
2223
import org.opensearch.sql.ppl.WhereCommandIT;
2324

2425
public class CalciteWhereCommandIT extends WhereCommandIT {
@@ -140,4 +141,15 @@ public void testScriptFilterOnDifferentNestedHierarchyShouldThrow() throws IOExc
140141
"Accessing multiple nested fields under different hierarchies in script is not supported:"
141142
+ " [author.books.reviews, author.books]");
142143
}
144+
145+
@Test
146+
public void testAggFilterOnNestedFields() throws IOException {
147+
JSONObject result =
148+
executeQuery(
149+
StringUtils.format(
150+
"source=%s | stats count(eval(author.name < 'K')) as george_and_jk",
151+
TEST_INDEX_CASCADED_NESTED));
152+
verifySchema(result, schema("george_and_jk", "bigint"));
153+
verifyDataRows(result, rows(2));
154+
}
143155
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
LogicalAggregate(group=[{}], george_and_jk=[COUNT($0)])
5+
LogicalProject($f1=[CASE(<($7, 'K'), 1, null:NULL)])
6+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_cascaded_nested]])
7+
physical: |
8+
EnumerableLimit(fetch=[10000])
9+
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_cascaded_nested]], PushDownContext=[[AGGREGATION->rel#:LogicalAggregate.NONE.[](input=RelSubset#,group={},george_and_jk=COUNT() FILTER $0)], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":0,"timeout":"1m","aggregations":{"george_and_jk":{"filter":{"nested":{"query":{"range":{"author.name":{"from":null,"to":"K","include_lower":true,"include_upper":false,"boost":1.0}}},"path":"author","ignore_unmapped":false,"score_mode":"none","boost":1.0}},"aggregations":{"george_and_jk":{"value_count":{"field":"_index"}}}}}}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
LogicalAggregate(group=[{}], george_and_jk=[COUNT($0)])
5+
LogicalProject($f1=[CASE(<($7, 'K'), 1, null:NULL)])
6+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_cascaded_nested]])
7+
physical: |
8+
EnumerableLimit(fetch=[10000])
9+
EnumerableAggregate(group=[{}], george_and_jk=[COUNT() FILTER $0])
10+
EnumerableCalc(expr#0..13=[{inputs}], expr#14=['K'], expr#15=[<($t7, $t14)], expr#16=[IS TRUE($t15)], $f1=[$t16])
11+
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_cascaded_nested]])

0 commit comments

Comments
 (0)