danny0405 commented on a change in pull request #1310: [CALCITE-3113]
Equivalent MutableAggregates with different row types should match with each
other.
URL: https://github.com/apache/calcite/pull/1310#discussion_r303277437
##########
File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
##########
@@ -531,8 +531,22 @@ assert equalType(
final UnifyResult result = rule.apply(call);
if (result != null) {
++count;
- attempted.add(new Replacement(result.call.query,
result.result));
- MutableRel parent =
result.call.query.replaceInParent(result.result);
+ final MutableRel result1;
+ if (targetDescendant == target
+ &&
!result.result.rowType.equals(result.call.query.rowType)) {
+ // When target and query match with each other but have
different
+ // rowTypes, we add a MutableProject for compensation, thus
to
+ // assure the rowType of the replaced is exactly as before.
+ final RexBuilder rexBuilder = target.cluster.getRexBuilder();
+ List<RexNode> projects = new ArrayList<>(
+ rexBuilder.identityProjects(result.call.query.rowType));
+ result1 = MutableProject.of(
+ result.call.query.rowType, result.result, projects);
+ } else {
+ result1 = result.result;
Review comment:
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.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services