[CALCITE-739] Extend RexUtil.pullFactors to recognize additional common factors (follow-up) - #5286
Merged
Merged
Conversation
…on factors (follow-up)
Contributor
Author
|
@xuzifu666 sorry I did not participate of the review of your original PR #5246, could you please take a look at this follow-up proposal? |
xuzifu666
approved these changes
Sep 23, 2026
xuzifu666
left a comment
Member
There was a problem hiding this comment.
LGTM, thank you for the improvement! normalizeComparison is indeed unnecessary.
|
Contributor
Author
|
Thanks for the review @xuzifu666 ! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Jira Link
CALCITE-739
Changes Proposed
The original patch for CALCITE-739 (51e6cb1) implemented some extra factoring, but it also (unnecessarily) may alter the "orientation" of comparison predicates. This can have a certain impact on downstream projects which verify plan forms, e.g. in Hive we detected 150+ tests that fail simply because they expect
$a=$band now they get$b=$a(without any extra pull factors being involved).This was not the purpose of CALCITE-739.
With some minor adjustments, we should be able to maintain the new feature of extra factoring in
RexUtil.pullFactorswithout changing unnecessarily the authored orientation of certain predicates:default: return normalizeComparison(rex);inpull()(RexUtil.java:2970): it does no factoring at all, it is pure canonicalizationcommonFactors, store the original as the value:map.put(normalized, conjunction) rather thanmap.put(normalized, normalized), so pulled-out factors keep their authored orientationThese changes will reduce the side effects of the original commit (facilitating the eventual upgrade to 1.43 for downstream projects that test plan shapes), keeping the improvement of CALCITE-739 (see specific test
RexProgramTest#testSimplifyComparisonSymmetrystill passes with the proposed adjustment).