keatoooon commented on code in PR #3452:
URL: https://github.com/apache/calcite/pull/3452#discussion_r1346428537


##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java:
##########
@@ -666,6 +666,29 @@ static class JoinConditionBasedPredicateInference {
       equivalence = BitSets.closure(equivalence);
     }
 
+    /**
+     * As RexPermuteInputsShuttle, with one exception. When visiting an 
inputRef,
+     * it will replace the type of the InputRef with the type found in the 
input fields,
+     * instead of keeping the original type. This is used within
+     * when generating the Left/RightInferredPredicates, to avoid nullability 
mismatches
+     * between the types of the join and the types of the inputs.
+     */
+    private class TypeChangingRexPermuteInputsShuttle
+        extends org.apache.calcite.rex.RexPermuteInputsShuttle {
+
+      TypeChangingRexPermuteInputsShuttle(Mappings.TargetMapping mapping, 
RelNode... inputs) {
+        super(mapping, inputs);
+      }
+
+      @Override public RexNode visitInputRef(RexInputRef local) {
+        final int index = local.getIndex();
+        int target = mapping.getTarget(index);
+        return new RexInputRef(
+            target,
+            fields.get(target).getType());

Review Comment:
   I think in order to check that the two types are equivalent except for 
nullability, I would need to have access to a typefactory, so I could do 
something like `typefatory.createTypeWithNullability(t1, 
t2.isNullable()).equals(t1)`.
   
   For now, I added a sanity check to confirm that the two types are of the 
same type family. I'm not certain if this is a good check for compatibility, 
and am open to changing 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.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to