Skip to content

Commit f51f1af

Browse files
committed
Test filter on both nested and root level fields
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 01c6b1e commit f51f1af

6 files changed

Lines changed: 46 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2376,11 +2376,22 @@ public void testExplainBWC() throws IOException {
23762376
@Test
23772377
public void testFilterOnNestedFields() throws IOException {
23782378
assertYamlEqualsIgnoreId(
2379-
loadExpectedPlan("filter_on_nested.yaml"),
2379+
loadExpectedPlan("filter_nested.yaml"),
23802380
explainQueryYaml(
23812381
StringUtils.format(
23822382
"source=%s | eval proj_name_len=length(projects.name) | fields projects.name,"
23832383
+ " proj_name_len | where proj_name_len > 29",
23842384
TEST_INDEX_DEEP_NESTED)));
23852385
}
2386+
2387+
@Test
2388+
public void testFilterOnNestedAndRootFields() throws IOException {
2389+
assertYamlEqualsIgnoreId(
2390+
loadExpectedPlan("filter_root_and_nested.yaml"),
2391+
// city.name is not in a nested object
2392+
explainQueryYaml(
2393+
StringUtils.format(
2394+
"source=%s | where city.name = 'Seattle' and length(projects.name) > 29",
2395+
TEST_INDEX_DEEP_NESTED)));
2396+
}
23862397
}

integ-test/src/test/resources/expectedOutput/calcite/filter_on_nested.yaml renamed to integ-test/src/test/resources/expectedOutput/calcite/filter_nested.yaml

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
LogicalProject(accounts=[$0], projects=[$2], city=[$4], account=[$8])
5+
LogicalFilter(condition=[AND(=($7, 'Seattle'), >(CHAR_LENGTH($3), 29))])
6+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_deep_nested]])
7+
physical: |
8+
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_deep_nested]], PushDownContext=[[PROJECT->[accounts, projects, projects.name, city, city.name, account], SCRIPT->AND(=($4, 'Seattle'), >(CHAR_LENGTH($2), 29)), PROJECT->[accounts, projects, city, account], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"bool":{"must":[{"term":{"city.name":{"value":"Seattle","boost":1.0}}},{"nested":{"query":{"script":{"script":{"source":"{\"langType\":\"calcite\",\"script\":\"rO0ABXQCIXsKICAib3AiOiB7CiAgICAibmFtZSI6ICI+IiwKICAgICJraW5kIjogIkdSRUFURVJfVEhBTiIsCiAgICAic3ludGF4IjogIkJJTkFSWSIKICB9LAogICJvcGVyYW5kcyI6IFsKICAgIHsKICAgICAgIm9wIjogewogICAgICAgICJuYW1lIjogIkNIQVJfTEVOR1RIIiwKICAgICAgICAia2luZCI6ICJDSEFSX0xFTkdUSCIsCiAgICAgICAgInN5bnRheCI6ICJGVU5DVElPTiIKICAgICAgfSwKICAgICAgIm9wZXJhbmRzIjogWwogICAgICAgIHsKICAgICAgICAgICJkeW5hbWljUGFyYW0iOiAwLAogICAgICAgICAgInR5cGUiOiB7CiAgICAgICAgICAgICJ0eXBlIjogIlZBUkNIQVIiLAogICAgICAgICAgICAibnVsbGFibGUiOiB0cnVlLAogICAgICAgICAgICAicHJlY2lzaW9uIjogLTEKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIF0KICAgIH0sCiAgICB7CiAgICAgICJkeW5hbWljUGFyYW0iOiAxLAogICAgICAidHlwZSI6IHsKICAgICAgICAidHlwZSI6ICJJTlRFR0VSIiwKICAgICAgICAibnVsbGFibGUiOiBmYWxzZQogICAgICB9CiAgICB9CiAgXQp9\"}","lang":"opensearch_compounded_script","params":{"utcTimestamp": 0,"SOURCES":[0,2],"DIGESTS":["projects.name",29]}},"boost":1.0}},"path":"projects","ignore_unmapped":false,"score_mode":"none","boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"_source":{"includes":["accounts","projects","city","account"],"excludes":[]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)])

integ-test/src/test/resources/expectedOutput/calcite_no_pushdown/filter_on_nested.yaml renamed to integ-test/src/test/resources/expectedOutput/calcite_no_pushdown/filter_nested.yaml

File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
LogicalProject(accounts=[$0], projects=[$2], city=[$4], account=[$8])
5+
LogicalFilter(condition=[AND(=($7, 'Seattle'), >(CHAR_LENGTH($3), 29))])
6+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_deep_nested]])
7+
physical: |
8+
EnumerableLimit(fetch=[10000])
9+
EnumerableCalc(expr#0..15=[{inputs}], expr#16=['Seattle':VARCHAR], expr#17=[=($t7, $t16)], expr#18=[CHAR_LENGTH($t3)], expr#19=[29], expr#20=[>($t18, $t19)], expr#21=[AND($t17, $t20)], accounts=[$t0], projects=[$t2], city=[$t4], account=[$t8], $condition=[$t21])
10+
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_deep_nested]])

integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/4508.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,19 @@ setup:
9292
- match: { total: 2 }
9393
- match: {"schema": [{"name": "id", "type": "string"}, {"name": "name", "type": "string"}, {"name": "NameLen", "type": "int"}]}
9494
- match: {"datarows": [["order2", "banana", 6], ["order3", "orange", 6]]}
95+
96+
---
97+
"filter on both nested and root level fields ":
98+
- skip:
99+
features:
100+
- headers
101+
- do:
102+
headers:
103+
Content-Type: 'application/json'
104+
ppl:
105+
body:
106+
query: source=test_nested_eval_filter | eval NameLen=LENGTH(items.name) | where NameLen> 5 and id = 'order2' | fields id, items.name, NameLen
107+
108+
- match: { total: 1 }
109+
- match: {"schema": [{"name": "id", "type": "string"}, {"name": "items.name", "type": "string"}, {"name": "NameLen", "type": "int"}]}
110+
- match: {"datarows": [["order2", "banana", 6]]}

0 commit comments

Comments
 (0)