-
Notifications
You must be signed in to change notification settings - Fork 222
fix: push down date range filters wrapped by redundant date conversions (both operands, v2 + Calcite) #5681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
burnthm
wants to merge
8
commits into
opensearch-project:main
Choose a base branch
from
burnthm:fix-timestamp-cast-pushdown
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8422367
fix: push down date filter wrapped by redundant date cast
burnthm 64dedec
refactor: harden unwrapReference precondition
burnthm b649b72
fix: only fold a date cast when it does not change the type
burnthm 24d4949
fix: push down date filter wrapped by redundant date cast (Calcite)
burnthm 60c39b2
fix: restrict the Calcite fold to date conversion operators
burnthm 7d6285d
test: add integration coverage for the date-cast fold
burnthm 9f4c7cb
fix: push down when the range bound is wrapped by a date conversion
burnthm 04be095
fix: only resolve a bound conversion matching the field's date type
burnthm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
integ-test/src/test/resources/expectedOutput/calcite/explain_filter_last_day_no_push.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| calcite: | ||
| logical: | | ||
| LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT]) | ||
| LogicalFilter(condition=[=(LAST_DAY($0), DATE('2018-11-30':VARCHAR))]) | ||
| LogicalProject(yyyy-MM-dd=[$83]) | ||
| CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_date_formats]]) | ||
| physical: | | ||
| CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_date_formats]], PushDownContext=[[PROJECT->[yyyy-MM-dd], SCRIPT->=(LAST_DAY($0), '2018-11-30'), LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"script":{"script":{"source":"{\"langType\":\"calcite\",\"script\":\"rO0ABXQDfHsKICAib3AiOiB7CiAgICAibmFtZSI6ICI9IiwKICAgICJraW5kIjogIkVRVUFMUyIsCiAgICAic3ludGF4IjogIkJJTkFSWSIKICB9LAogICJvcGVyYW5kcyI6IFsKICAgIHsKICAgICAgIm9wIjogewogICAgICAgICJuYW1lIjogIkxBU1RfREFZIiwKICAgICAgICAia2luZCI6ICJPVEhFUl9GVU5DVElPTiIsCiAgICAgICAgInN5bnRheCI6ICJGVU5DVElPTiIKICAgICAgfSwKICAgICAgIm9wZXJhbmRzIjogWwogICAgICAgIHsKICAgICAgICAgICJkeW5hbWljUGFyYW0iOiAwLAogICAgICAgICAgInR5cGUiOiB7CiAgICAgICAgICAgICJ1ZHQiOiAiRVhQUl9EQVRFIiwKICAgICAgICAgICAgInR5cGUiOiAiVkFSQ0hBUiIsCiAgICAgICAgICAgICJudWxsYWJsZSI6IHRydWUsCiAgICAgICAgICAgICJwcmVjaXNpb24iOiAtMQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgXSwKICAgICAgImNsYXNzIjogIm9yZy5vcGVuc2VhcmNoLnNxbC5leHByZXNzaW9uLmZ1bmN0aW9uLlVzZXJEZWZpbmVkRnVuY3Rpb25CdWlsZGVyJDEiLAogICAgICAidHlwZSI6IHsKICAgICAgICAidWR0IjogIkVYUFJfREFURSIsCiAgICAgICAgInR5cGUiOiAiVkFSQ0hBUiIsCiAgICAgICAgIm51bGxhYmxlIjogdHJ1ZSwKICAgICAgICAicHJlY2lzaW9uIjogLTEKICAgICAgfSwKICAgICAgImRldGVybWluaXN0aWMiOiB0cnVlLAogICAgICAiZHluYW1pYyI6IGZhbHNlCiAgICB9LAogICAgewogICAgICAiZHluYW1pY1BhcmFtIjogMSwKICAgICAgInR5cGUiOiB7CiAgICAgICAgInVkdCI6ICJFWFBSX0RBVEUiLAogICAgICAgICJ0eXBlIjogIlZBUkNIQVIiLAogICAgICAgICJudWxsYWJsZSI6IHRydWUsCiAgICAgICAgInByZWNpc2lvbiI6IC0xCiAgICAgIH0KICAgIH0KICBdCn0=\"}","lang":"opensearch_compounded_script","params":{"utcTimestamp": 0,"SOURCES":[0,2],"DIGESTS":["yyyy-MM-dd","2018-11-30"]}},"boost":1.0}},"_source":{"includes":["yyyy-MM-dd"]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)]) |
9 changes: 9 additions & 0 deletions
9
...rc/test/resources/expectedOutput/calcite/explain_filter_push_timestamp_wrapped_bound.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| calcite: | ||
| logical: | | ||
| LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT]) | ||
| LogicalProject(account_number=[$0], firstname=[$1], address=[$2], birthdate=[$3], gender=[$4], city=[$5], lastname=[$6], balance=[$7], employer=[$8], state=[$9], age=[$10], email=[$11], male=[$12]) | ||
| LogicalFilter(condition=[<($3, TIMESTAMP('2018-11-09 00:00:00':VARCHAR))]) | ||
| LogicalFilter(condition=[>($3, TIMESTAMP('2016-12-08 00:00:00':VARCHAR))]) | ||
| CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]]) | ||
| physical: | | ||
| CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]], PushDownContext=[[PROJECT->[account_number, firstname, address, birthdate, gender, city, lastname, balance, employer, state, age, email, male], FILTER->SEARCH($3, Sarg[('2016-12-08 00:00:00':VARCHAR..'2018-11-09 00:00:00':VARCHAR)]:VARCHAR), LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"range":{"birthdate":{"from":"2016-12-08T00:00:00.000Z","to":"2018-11-09T00:00:00.000Z","include_lower":false,"include_upper":false,"format":"date_time","boost":1.0}}},"_source":{"includes":["account_number","firstname","address","birthdate","gender","city","lastname","balance","employer","state","age","email","male"]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)]) |
9 changes: 9 additions & 0 deletions
9
...rc/test/resources/expectedOutput/calcite/explain_filter_push_timestamp_wrapped_field.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| calcite: | ||
| logical: | | ||
| LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT]) | ||
| LogicalProject(account_number=[$0], firstname=[$1], address=[$2], birthdate=[$3], gender=[$4], city=[$5], lastname=[$6], balance=[$7], employer=[$8], state=[$9], age=[$10], email=[$11], male=[$12]) | ||
| LogicalFilter(condition=[<(TIMESTAMP($3), TIMESTAMP('2018-11-09 00:00:00':VARCHAR))]) | ||
| LogicalFilter(condition=[>(TIMESTAMP($3), TIMESTAMP('2016-12-08 00:00:00':VARCHAR))]) | ||
| CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]]) | ||
| physical: | | ||
| CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]], PushDownContext=[[PROJECT->[account_number, firstname, address, birthdate, gender, city, lastname, balance, employer, state, age, email, male], FILTER->SEARCH(TIMESTAMP($3), Sarg[('2016-12-08 00:00:00':VARCHAR..'2018-11-09 00:00:00':VARCHAR)]:VARCHAR), LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"range":{"birthdate":{"from":"2016-12-08T00:00:00.000Z","to":"2018-11-09T00:00:00.000Z","include_lower":false,"include_upper":false,"format":"date_time","boost":1.0}}},"_source":{"includes":["account_number","firstname","address","birthdate","gender","city","lastname","balance","employer","state","age","email","male"]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)]) |
10 changes: 10 additions & 0 deletions
10
...rc/test/resources/expectedOutput/calcite_no_pushdown/explain_filter_last_day_no_push.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| calcite: | ||
| logical: | | ||
| LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT]) | ||
| LogicalFilter(condition=[=(LAST_DAY($0), DATE('2018-11-30':VARCHAR))]) | ||
| LogicalProject(yyyy-MM-dd=[$83]) | ||
| CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_date_formats]]) | ||
| physical: | | ||
| EnumerableLimit(fetch=[10000]) | ||
| EnumerableCalc(expr#0..94=[{inputs}], expr#95=[LAST_DAY($t83)], expr#96=['2018-11-30':EXPR_DATE VARCHAR], expr#97=[=($t95, $t96)], yyyy-MM-dd=[$t83], $condition=[$t97]) | ||
| CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_date_formats]]) |
11 changes: 11 additions & 0 deletions
11
...urces/expectedOutput/calcite_no_pushdown/explain_filter_push_timestamp_wrapped_bound.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| calcite: | ||
| logical: | | ||
| LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT]) | ||
| LogicalProject(account_number=[$0], firstname=[$1], address=[$2], birthdate=[$3], gender=[$4], city=[$5], lastname=[$6], balance=[$7], employer=[$8], state=[$9], age=[$10], email=[$11], male=[$12]) | ||
| LogicalFilter(condition=[<($3, TIMESTAMP('2018-11-09 00:00:00':VARCHAR))]) | ||
| LogicalFilter(condition=[>($3, TIMESTAMP('2016-12-08 00:00:00':VARCHAR))]) | ||
| CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]]) | ||
| physical: | | ||
| EnumerableLimit(fetch=[10000]) | ||
| EnumerableCalc(expr#0..18=[{inputs}], expr#19=[Sarg[('2016-12-08 00:00:00':VARCHAR..'2018-11-09 00:00:00':VARCHAR)]:VARCHAR], expr#20=[SEARCH($t3, $t19)], proj#0..12=[{exprs}], $condition=[$t20]) | ||
| CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]]) |
11 changes: 11 additions & 0 deletions
11
...urces/expectedOutput/calcite_no_pushdown/explain_filter_push_timestamp_wrapped_field.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| calcite: | ||
| logical: | | ||
| LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT]) | ||
| LogicalProject(account_number=[$0], firstname=[$1], address=[$2], birthdate=[$3], gender=[$4], city=[$5], lastname=[$6], balance=[$7], employer=[$8], state=[$9], age=[$10], email=[$11], male=[$12]) | ||
| LogicalFilter(condition=[<(TIMESTAMP($3), TIMESTAMP('2018-11-09 00:00:00':VARCHAR))]) | ||
| LogicalFilter(condition=[>(TIMESTAMP($3), TIMESTAMP('2016-12-08 00:00:00':VARCHAR))]) | ||
| CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]]) | ||
| physical: | | ||
| EnumerableLimit(fetch=[10000]) | ||
| EnumerableCalc(expr#0..18=[{inputs}], expr#19=[TIMESTAMP($t3)], expr#20=[Sarg[('2016-12-08 00:00:00':VARCHAR..'2018-11-09 00:00:00':VARCHAR)]:VARCHAR], expr#21=[SEARCH($t19, $t20)], proj#0..12=[{exprs}], $condition=[$t21]) | ||
| CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]]) |
20 changes: 20 additions & 0 deletions
20
integ-test/src/test/resources/expectedOutput/ppl/explain_filter_last_day_no_push.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| root: | ||
| name: ProjectOperator | ||
| description: | ||
| fields: "[yyyy-MM-dd]" | ||
| children: | ||
| - name: FilterOperator | ||
| description: | ||
| conditions: "=(last_day(yyyy-MM-dd), date(\"2018-11-30\"))" | ||
| children: | ||
| - name: ProjectOperator | ||
| description: | ||
| fields: "[yyyy-MM-dd]" | ||
| children: | ||
| - name: OpenSearchIndexScan | ||
| description: | ||
| request: "OpenSearchQueryRequest(indexName=opensearch-sql_test_index_date_formats,\ | ||
| \ sourceBuilder={\"from\":0,\"size\":10000,\"timeout\":\"1m\",\"\ | ||
| _source\":{\"includes\":[\"yyyy-MM-dd\"]}}, pitId=*,\ | ||
| \ cursorKeepAlive=1m, searchAfter=null, searchResponse=null)" | ||
| children: [] |
19 changes: 19 additions & 0 deletions
19
...st/src/test/resources/expectedOutput/ppl/explain_filter_push_timestamp_wrapped_bound.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| root: | ||
| name: ProjectOperator | ||
| description: | ||
| fields: "[account_number, firstname, address, birthdate, gender, city, lastname,\ | ||
| \ balance, employer, state, age, email, male]" | ||
| children: | ||
| - name: OpenSearchIndexScan | ||
| description: | ||
| request: "OpenSearchQueryRequest(indexName=opensearch-sql_test_index_bank,\ | ||
| \ sourceBuilder={\"from\":0,\"size\":10000,\"timeout\":\"1m\",\"query\"\ | ||
| :{\"bool\":{\"filter\":[{\"range\":{\"birthdate\":{\"from\":null,\"to\"\ | ||
| :1541721600000,\"include_lower\":true,\"include_upper\":false,\"boost\"\ | ||
| :1.0}}},{\"range\":{\"birthdate\":{\"from\":1481155200000,\"to\":null,\"\ | ||
| include_lower\":false,\"include_upper\":true,\"boost\":1.0}}}],\"adjust_pure_negative\"\ | ||
| :true,\"boost\":1.0}},\"_source\":{\"includes\":[\"account_number\",\"firstname\"\ | ||
| ,\"address\",\"birthdate\",\"gender\",\"city\",\"lastname\",\"balance\"\ | ||
| ,\"employer\",\"state\",\"age\",\"email\",\"male\"]}}, pitId=*,\ | ||
| \ cursorKeepAlive=1m, searchAfter=null, searchResponse=null)" | ||
| children: [] |
19 changes: 19 additions & 0 deletions
19
...st/src/test/resources/expectedOutput/ppl/explain_filter_push_timestamp_wrapped_field.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| root: | ||
| name: ProjectOperator | ||
| description: | ||
| fields: "[account_number, firstname, address, birthdate, gender, city, lastname,\ | ||
| \ balance, employer, state, age, email, male]" | ||
| children: | ||
| - name: OpenSearchIndexScan | ||
| description: | ||
| request: "OpenSearchQueryRequest(indexName=opensearch-sql_test_index_bank,\ | ||
| \ sourceBuilder={\"from\":0,\"size\":10000,\"timeout\":\"1m\",\"query\"\ | ||
| :{\"bool\":{\"filter\":[{\"range\":{\"birthdate\":{\"from\":null,\"to\"\ | ||
| :1541721600000,\"include_lower\":true,\"include_upper\":false,\"boost\"\ | ||
| :1.0}}},{\"range\":{\"birthdate\":{\"from\":1481155200000,\"to\":null,\"\ | ||
| include_lower\":false,\"include_upper\":true,\"boost\":1.0}}}],\"adjust_pure_negative\"\ | ||
| :true,\"boost\":1.0}},\"_source\":{\"includes\":[\"account_number\",\"firstname\"\ | ||
| ,\"address\",\"birthdate\",\"gender\",\"city\",\"lastname\",\"balance\"\ | ||
| ,\"employer\",\"state\",\"age\",\"email\",\"male\"]}}, pitId=*,\ | ||
| \ cursorKeepAlive=1m, searchAfter=null, searchResponse=null)" | ||
| children: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the redundant cast on field, it should be done earlier, e.g., V3's CalciteRel/RexNodeVisitor or V2's Analyzer as part of logical planning/optimization. For V3, is this not optimized due to time related type are UDT in our engine? Because I thought this optimization should be in Calcite builtin rule.