-
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-3113] Equivalent MutableAggregates with different row types should match with each other. #1310
Conversation
1a3b707
to
52b12b9
Compare
core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
Outdated
Show resolved
Hide resolved
What do we do elsewhere (e.g. in RelOptRules)? Do we check whether row-types are the same modulo field names? |
My concern is the same, in |
@julianhyde @danny0405 THX a lot for review ! |
if (targetDescendant == target) { | ||
// A real substitution happens. We purge the attempted | ||
// replacement list and add them into substitution list. | ||
// Meanwhile we stop matching the descendants and jump | ||
// to the next subtree in pre-order traversal. | ||
assert result1.rowType.equals(result.call.query.rowType) | ||
: Pair.of(result1, result.call.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.
This assert is not that necessary, because it is always true now.
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.
OK, I will remove it.
result1 = MutableProject.of( | ||
result.call.query.rowType, result.result, projects); | ||
} else { | ||
result1 = result.result; |
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.
Instead of new a MutableProject, can we just check the project list of the result row type ? If i'm not mistaken, only if the query and target have same row expressions but different alias can be matched, maybe we should only check the expression for alias.
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.
Sorry, I don't quite get it ~ Do you mean below ?
- No need to new a
MutableProject
, though the row type is different, we just let it go - Add a check/assert for the row type, we allow name mismatch, but other parts of row type should match with each other
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.
Sorry, I don't quite get it ~ Do you mean below ?
- No need to new a
MutableProject
, though the row type is different, we just let it go- Add a check/assert for the row type, we allow name mismatch, but other parts of row type should match with each other
Yeah, that is just what i mean.
final RexBuilder rexBuilder = target.cluster.getRexBuilder(); | ||
List<RexNode> projects = new ArrayList<>( | ||
rexBuilder.identityProjects(result.call.query.rowType)); | ||
result1 = MutableProject.of( |
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.
Let's give the result1
a more readable name, how about equivalentResult
?
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.
Yes, that'd better.
I have give some advices for my understanding. But i'm not sure if it is better or worse when we allow to match of materializedView with different row type. Because our planning rules only consider strict row type match for equivalent rel nodes. Maybe @jcamachor can give a better review. |
THX, @danny0405 for your comments, I'll update the patch soon. |
…should match with each other.
@julianhyde |
core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
Outdated
Show resolved
Hide resolved
LGTM |
THX @rubenada for approving ! |
private boolean rowTypesAreEquivalent( | ||
MutableRel rel0, MutableRel rel1, Litmus litmus) { | ||
// Validation checking for row type, but except for the field names. | ||
assert rel0.rowType.getFieldCount() == rel1.rowType.getFieldCount() |
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 comment seems redundant, because there is already a java doc comment for the method.
private boolean rowTypesAreEquivalent( | ||
MutableRel rel0, MutableRel rel1, Litmus litmus) { | ||
// Validation checking for row type, but except for the field names. | ||
assert rel0.rowType.getFieldCount() == rel1.rowType.getFieldCount() |
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.
Why we still use this single assert and the other use the litmus ?
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.
THX Danny,
I updated, please check~
@danny0405 |
…should match with each other(Jin Xing) The MaterializedView now can match with eath other if the row fields types equals but with different alias. close apache#1310
…should match with each other(Jin Xing) The MaterializedView now can match with eath other if the row fields types equals but with different alias. close apache#1310
In current code, below test case fails:
The reason is that
MutableRel
self-defined the identity mechanism. Obviously the materialization above should be used.This PR proposes to do equivalence checking for row types but except for the field names.
I added two test cases in
MaterializationTest
, without this change, both of them fails.