jinxing64 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_r303347138
 
 

 ##########
 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:
   Sorry, I don't quite get it ~ Do you mean below ?
   1. No need to new a `MutableProject`, though the row type is different, we 
just let it go
   2. Add a check/assert for the row type, we allow name mismatch, but other 
parts of row type should match with each other

----------------------------------------------------------------
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

Reply via email to