rubenada 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_r301669692
##########
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;
+ }
+ attempted.add(new Replacement(result.call.query, result1));
+ MutableRel parent = result.call.query.replaceInParent(result1);
Review comment:
`parent` variable is never used, we could get rid of it.
----------------------------------------------------------------
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