-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[CALCITE-6534] Adjust type when pulling up Calc in JoinUnifyRule #3921
Conversation
4b0f825
to
2233a96
Compare
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 personally I am not very familiar with this part of the codebase so I am not confident enough to approve. Based on the tests, this seems to work very well, though.
The code looks generally fine, I left most comments that could improve readability.
@Test void testLeftProjectOnRightJoinToJoinFailed() { | ||
* Assertion Error in JoinUnifyRule Due to Type Mismatch</a>. | ||
* | ||
* <p>Originally, this test was noMat due to a type mismatch. |
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 don't think this kind of comment is useful long term. It is useful for the reviewers of this PR, but not for maintaining the code. This comment would be better as a github comment rather than a code comment. Same for the subsequent comments.
private static boolean allProjectsNullable(List<RexNode> projects) { | ||
return projects.stream() | ||
.allMatch(project -> project.getType().isNullable()); | ||
/** Cast RexNode to the given type if only nullability differs. */ |
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 would also add "Otherwise throw". The current comment implies that in all other cases the type is left unchanged.
return true; | ||
} | ||
|
||
/** Determines if all projects are strong and the condition is always true. */ |
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.
not clear what the "projects" are and what the condition is given single input parameter. Maybe you can add @param
to describe where inputExplained comes from.
if (rightProjects != null && joinType.generatesNullsOn(1) | ||
&& !allProjectsNullable(rightProjects)) { | ||
return false; | ||
private static List<RexNode> shiftAndAdjustProjectExpr(MutableJoin query, MutableJoin target, |
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 JavaDoc at least for some parameters could also help.
In particular, what is the target?
} | ||
|
||
// In cases such as JoinOnLeftCalcToJoinUnifyRule and JoinOnCalcsToJoinUnifyRule rules, | ||
// the left calc need to be pulled up the target, initialize the converter. |
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.
should this be "where the left calc needs to be pulled up"?
@mihaibudiu Thanks for the review, this function both shift and type adjustments, and I think it's really not easy to understand, so I've optimized those comments and added more of them. |
* Working in rules: {@link JoinOnLeftCalcToJoinUnifyRule} <br/> | ||
* {@link JoinOnRightCalcToJoinUnifyRule} <br/> | ||
* {@link JoinOnCalcsToJoinUnifyRule} <br/> | ||
* | ||
* @param query MutableRel of query | ||
* @param target MutableRel of target |
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.
This information can be already obtained from the parameter declaration, the question I had is "what is the target?" Is the target the place where you are building the modified query?
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.
The naming here comes from UnifyRuleCall, UnifyRule is bottom-down matching, target means the RelNode of the mv that is trying to match.
If you're interested in this part, Refinement for Substitution-Based Materialized View Matching is a great resource
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.
Ideally that google doc would be posted somewhere publicly and linked from the code here.
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.
Sounds good, it can be done in other issue
You can squash the commits for merging |
b6f813d
to
d8ebdf8
Compare
Done✅ |
Quality Gate passedIssues Measures |
This PR addresses both [CALCITE-6534] and [CALCITE-6528] and is based on [CALCITE-6501]. For the problem of nullablility due to Join null-side, if RexNode satisfies null-if-null, we will adjust the nullability, if not, we should reject this rewrite regardless of the nullablility.