[CALCITE-2888] Enhance RexImplicationChecker to better handle cast#1081
[CALCITE-2888] Enhance RexImplicationChecker to better handle cast#1081jh3507 wants to merge 1 commit intoapache:mainfrom
Conversation
| } | ||
|
|
||
| private static RexNode convertAndRemoveCast(RexBuilder builder, RexExecutor executor, | ||
| RexNode literal, RelDataType toType) { |
There was a problem hiding this comment.
the name literal is a little bit misleading, because it may not be literal.
|
|
||
| public static DataContext of(RelDataType rowType, RexNode rex) { | ||
| return of(rowType, rex, null, null); | ||
| } |
There was a problem hiding this comment.
This has come from the previous definition. I think useless is somewhat subjective expression. This method is a public static method in a public class. I personally don't make this function call, but someone might be already using it. I didn't want to abruptly remove a public method. Also, giving nulls to builder and executor would make it possible to bypass the executor so that the output you get from it would be exactly the same as before. So, I think this can be useful especially for those who think this change is not necessary :) That being said, I am okay with removing existing 'of' methods if the community is okay with it.
Also, as far as I know, this can never be a constructor.
|
-1, I think it's not a good idea to make so muck changes just to move constant reduction logic into RexImplicationChecker, because there is a rule/rules can do this. Actually for production, the RexExecutor is pluggable for users, so the cast is not much big problem. |
| * @return Objects returned after applying generated code with dataValues. | ||
| */ | ||
| Object[] execute(RexBuilder rexBuilder, List<RexNode> exps, | ||
| RelDataType rowType, DataContext dataValues); |
There was a problem hiding this comment.
-1, this should not be made into an interface method, because from this signature or comment, user can see nothing about the relationship with RexExecutable which could got from another method.
There was a problem hiding this comment.
I agree with the point that the comment is misleaing. Thanks for noticing it. I have updated the comment. But, in terms of what should be included in the interface, I think one that is commonly used among the various implementations should go into the interface. execution is needed when checking if a value is satisfiable in the filter. So, I think it should be implemented. Delegating it to the existing RexExecutionImpl would be one possible solution if implementing it is too much effort.
- make RexImplicationChecker use executor's reduce function when generating value for literal(in VisitorDataContext) - allow other versions of RexExecutor Change-Id: Ie343535c1061d0927356aa37332c048306c5739a
80f411d to
ca27fe9
Compare
49cb002 to
8768a23
Compare
8a5cf83 to
cf7f71b
Compare
…ng) & [CALCITE-3797] RelMdPredicates should not assume the RexExecutor instance is RexExecutorImpl (apache#9) ## DX-94069: [CALCITE-3439] Support Intersect and Minus in RelMdPredicates (Jin Xing) <!-- Explanation of what you are cherry picking and why. If you are cherry picking multiple commits, you should detail what overall problem you are solving. --> This pr is part of the efforts for Dremio Calcite 1.22 migration. This cherry-pick focuses on adding support for Intersect and Minus in RelMdPredicates, while currently only Union is supported. Dremio side change: dremio/dremio#8130 ### Cherry picks: <!-- List the commits that were cherry picked below. Make sure to use the commit sha from the branch you are cherry picking from (e.g. master), not from your PR branch.--> ---- **Commit:** 76f9847 **Conflicts Resolved:** {If applicable, explanation of any deviations from the original commit that were made.} 1. It is noteworthy that Dremio build hit an NPE with CALCITE-3439 cherry-pick alone, which is caused by the null executor set [during DremioVolcanoPlanner initialization when building RelOptPlanner in RelOptPlannerSpecBuild.](https://github.com/dremio/dremio/blob/33772cbe1af9d629e7512c86ed1b8430a7fad37d/community/sabot/kernel/src/test/java/com/dremio/test/specs/RelOptPlannerSpecBuild.java#L46). Therefore, we club [CALCITE-3797](https://github.com/sabrinayuu/dcalcite/tree/CALCITE-3797) with [CALCITE-3439](https://github.com/sabrinayuu/dcalcite/tree/CALCITE-3439) because CALCITE-3797 brings in [the fix](apache@bf3fb49#diff-23e11f70f80e09eb099a586a4ae5ed00807fd9412045427c37491cac2dd6946aR425), with which `getPredicates(Union union, RelMetadataQuery mq)` will use a constant executor `RexUtil.EXECUTOR` when the planner has a null executor. 2. To address the flaky test RelMetadataTest.testPullUpPredicatesFromUnion2 caused by [the same hash code shared by predicates with different expression order](dremio/calcite#9 (comment)), we partially cherry picked [CALCITE-4073](apache@a4fa054#diff-6137557db145272ce78c72b01e41c06950b47362fb40d9f9268fec3ca84cd11cR2047-R2053). **Original Description:** https://issues.apache.org/jira/browse/CALCITE-3439 Currently only Union is supported in RelMdPredicates. We might also support Intersect and Minus; This issue was found when resolving [CALCITE-3428](https://issues.apache.org/jira/browse/CALCITE-3428) ---- sabrinayuu/dcalcite#1 **Commit:** bf3fb49 **Conflicts Resolved:** Ran into discrepancies when updating file RexImplicationChecker: Upstream: https://github.com/apache/calcite/blob/calcite-1.22.0/core/src/main/java/org/apache/calcite/plan/RexImplicationChecker.java#L252-L258 Our branch: https://github.com/dremio/calcite/blob/1.22-dremio/core/src/main/java/org/apache/calcite/plan/RexImplicationChecker.java#L267-L269 The difference is caused by [DX-14980](https://dremio.atlassian.net/browse/DX-14980?focusedCommentId=258804) which introduced a fix only on Dremio Calcite fork to enhance the cast handling in RexImplicationChecker but the same change [did not make it to the upstream Calcite... ](apache#1081) [(CALCITE-2888)](https://issues.apache.org/jira/browse/CALCITE-2888). Fortunately, the difference that matters to this pr is a minor code refactor that can be reverted and then apply the original cherrypick. **Original Description:** https://issues.apache.org/jira/browse/CALCITE-3797 The RexExecutor is actually pluggable, we should not do such an assumption. --------- Co-authored-by: jinxing <jinxing.corey@gmail.com> Co-authored-by: yuzhao.cyz <yuzhao.cyz@gmail.com>
…ng) & [CALCITE-3797] RelMdPredicates should not assume the RexExecutor instance is RexExecutorImpl (apache#9) RelMdPredicates (Jin Xing) <!-- Explanation of what you are cherry picking and why. If you are cherry picking multiple commits, you should detail what overall problem you are solving. --> This pr is part of the efforts for Dremio Calcite 1.22 migration. This cherry-pick focuses on adding support for Intersect and Minus in RelMdPredicates, while currently only Union is supported. Dremio side change: dremio/dremio#8130 <!-- List the commits that were cherry picked below. Make sure to use the commit sha from the branch you are cherry picking from (e.g. master), not from your PR branch.--> ---- **Commit:** 76f9847 **Conflicts Resolved:** {If applicable, explanation of any deviations from the original commit that were made.} 1. It is noteworthy that Dremio build hit an NPE with CALCITE-3439 cherry-pick alone, which is caused by the null executor set [during DremioVolcanoPlanner initialization when building RelOptPlanner in RelOptPlannerSpecBuild.](https://github.com/dremio/dremio/blob/33772cbe1af9d629e7512c86ed1b8430a7fad37d/community/sabot/kernel/src/test/java/com/dremio/test/specs/RelOptPlannerSpecBuild.java#L46). Therefore, we club [CALCITE-3797](https://github.com/sabrinayuu/dcalcite/tree/CALCITE-3797) with [CALCITE-3439](https://github.com/sabrinayuu/dcalcite/tree/CALCITE-3439) because CALCITE-3797 brings in [the fix](apache@bf3fb49#diff-23e11f70f80e09eb099a586a4ae5ed00807fd9412045427c37491cac2dd6946aR425), with which `getPredicates(Union union, RelMetadataQuery mq)` will use a constant executor `RexUtil.EXECUTOR` when the planner has a null executor. 2. To address the flaky test RelMetadataTest.testPullUpPredicatesFromUnion2 caused by [the same hash code shared by predicates with different expression order](dremio/calcite#9 (comment)), we partially cherry picked [CALCITE-4073](apache@a4fa054#diff-6137557db145272ce78c72b01e41c06950b47362fb40d9f9268fec3ca84cd11cR2047-R2053). **Original Description:** https://issues.apache.org/jira/browse/CALCITE-3439 Currently only Union is supported in RelMdPredicates. We might also support Intersect and Minus; This issue was found when resolving [CALCITE-3428](https://issues.apache.org/jira/browse/CALCITE-3428) ---- sabrinayuu/dcalcite#1 **Commit:** bf3fb49 **Conflicts Resolved:** Ran into discrepancies when updating file RexImplicationChecker: Upstream: https://github.com/apache/calcite/blob/calcite-1.22.0/core/src/main/java/org/apache/calcite/plan/RexImplicationChecker.java#L252-L258 Our branch: https://github.com/dremio/calcite/blob/1.22-dremio/core/src/main/java/org/apache/calcite/plan/RexImplicationChecker.java#L267-L269 The difference is caused by [DX-14980](https://dremio.atlassian.net/browse/DX-14980?focusedCommentId=258804) which introduced a fix only on Dremio Calcite fork to enhance the cast handling in RexImplicationChecker but the same change [did not make it to the upstream Calcite... ](apache#1081) [(CALCITE-2888)](https://issues.apache.org/jira/browse/CALCITE-2888). Fortunately, the difference that matters to this pr is a minor code refactor that can be reverted and then apply the original cherrypick. **Original Description:** https://issues.apache.org/jira/browse/CALCITE-3797 The RexExecutor is actually pluggable, we should not do such an assumption. --------- Co-authored-by: jinxing <jinxing.corey@gmail.com> Co-authored-by: yuzhao.cyz <yuzhao.cyz@gmail.com>
make RexImplicationChecker use executor's reduce function when generating a value for literal(VisitorDataContext)
allow other implementations of RexExecutor
Change-Id: Ie343535c1061d0927356aa37332c048306c5739a