clintropolis commented on a change in pull request #11434:
URL: https://github.com/apache/druid/pull/11434#discussion_r668562159



##########
File path: 
sql/src/main/java/org/apache/druid/sql/calcite/rule/DruidJoinRule.java
##########
@@ -283,7 +283,8 @@ static boolean canHandleCondition(final RexNode condition, 
final RelDataType lef
 
   private static boolean isLeftExpression(final RexNode rexNode, final int 
numLeftFields)
   {
-    return 
ImmutableBitSet.range(numLeftFields).contains(RelOptUtil.InputFinder.bits(rexNode));
+    ImmutableBitSet inputBitSet = RelOptUtil.InputFinder.bits(rexNode);
+    return !inputBitSet.isEmpty() && 
ImmutableBitSet.range(numLeftFields).contains(inputBitSet);

Review comment:
       might be worth leaving a comment about why the bitset shouldn't be empty

##########
File path: 
sql/src/main/java/org/apache/druid/sql/calcite/rule/FilterJoinExcludePushToChildRule.java
##########
@@ -292,4 +298,42 @@ private static boolean classifyFilters(List<RexNode> 
filters,
     // Did anything change?
     return !filtersToRemove.isEmpty();
   }
+
+  private void removeRedundantIsNotNullFilters(List<RexNode> joinFilters, 
JoinRelType joinType)
+  {
+    if (joinType != JoinRelType.INNER) {
+      return; // only works for inner joins
+    }
+
+    ImmutableList.Builder<RexNode> isNotNullFiltersBuilder = 
ImmutableList.builder();
+    ImmutableList.Builder<Pair<RexNode, RexNode>> 
equalityFiltersOperandBuilder = ImmutableList.builder();
+
+    for (RexNode joinFilter : joinFilters) {
+      List<RexNode> operands = ((RexCall) joinFilter).getOperands();
+      if (joinFilter.isA(SqlKind.IS_NOT_NULL)) {
+        isNotNullFiltersBuilder.add(joinFilter);
+      }
+      if (joinFilter.isA(SqlKind.EQUALS) && operands.size() == 2) {
+        equalityFiltersOperandBuilder.add(new Pair<>(operands.get(0), 
operands.get(1)));

Review comment:
       Can operands ever really be `null` valued here or will they always be a 
`RexNode`? Naively I would think not, and if true, I suggest maybe using 
`NonnullPair` instead.

##########
File path: 
sql/src/main/java/org/apache/druid/sql/calcite/rule/FilterJoinExcludePushToChildRule.java
##########
@@ -292,4 +298,42 @@ private static boolean classifyFilters(List<RexNode> 
filters,
     // Did anything change?
     return !filtersToRemove.isEmpty();
   }
+
+  private void removeRedundantIsNotNullFilters(List<RexNode> joinFilters, 
JoinRelType joinType)
+  {
+    if (joinType != JoinRelType.INNER) {
+      return; // only works for inner joins
+    }
+
+    ImmutableList.Builder<RexNode> isNotNullFiltersBuilder = 
ImmutableList.builder();
+    ImmutableList.Builder<Pair<RexNode, RexNode>> 
equalityFiltersOperandBuilder = ImmutableList.builder();
+
+    for (RexNode joinFilter : joinFilters) {
+      List<RexNode> operands = ((RexCall) joinFilter).getOperands();
+      if (joinFilter.isA(SqlKind.IS_NOT_NULL)) {
+        isNotNullFiltersBuilder.add(joinFilter);
+      }
+      if (joinFilter.isA(SqlKind.EQUALS) && operands.size() == 2) {

Review comment:
       should this be an else if?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to