hsyuan commented on a change in pull request #1346: [CALCITE-3223] 
Non-RexInputRef may fails the matching of FilterToProjectUnifyRule during 
'invert' by mistake
URL: https://github.com/apache/calcite/pull/1346#discussion_r313647498
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -1130,20 +1134,28 @@ protected MutableRel invert(MutableRel model, 
MutableRel input,
       }
       final List<RexNode> exprList = new ArrayList<>();
       final RexBuilder rexBuilder = model.cluster.getRexBuilder();
-      for (RelDataTypeField field : model.rowType.getFieldList()) {
-        exprList.add(rexBuilder.makeZeroLiteral(field.getType()));
+
+      // Initialize "exprList" with nulls.
+      for (int i = 0; i < model.rowType.getFieldCount(); i++) {
+        exprList.add(null);
       }
+      // Fill in "exprList" with list of "RexInputRef" by
+      // analyzing mapping information from "project".
       for (Ord<RexNode> expr : Ord.zip(project.projects)) {
         if (expr.e instanceof RexInputRef) {
           final int target = ((RexInputRef) expr.e).getIndex();
-          exprList.set(target,
-              rexBuilder.ensureType(expr.e.getType(),
-                  RexInputRef.of(expr.i, input.rowType),
-                  false));
-        } else {
-          throw MatchFailed.INSTANCE;
+          if (exprList.get(target) == null) {
+            exprList.set(target,
+                rexBuilder.ensureType(expr.e.getType(),
+                    RexInputRef.of(expr.i, input.rowType),
+                    false));
+          }
         }
       }
+      // If a column failed to be projected from "input", matching fails.
 
 Review comment:
   What if there is a literal in the project? The literal doesn't reference any 
column in the input.

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