clintropolis commented on a change in pull request #9648: SQL: More 
straightforward handling of join planning.
URL: https://github.com/apache/druid/pull/9648#discussion_r406107262
 
 

 ##########
 File path: 
sql/src/main/java/org/apache/druid/sql/calcite/rule/DruidJoinRule.java
 ##########
 @@ -148,4 +246,148 @@ static boolean canHandleCondition(final RexNode 
condition, final RelDataType lef
 
     return retVal;
   }
+
+  private static boolean isLeftExpression(final RexNode rexNode, final int 
numLeftFields)
+  {
+    return 
ImmutableBitSet.range(numLeftFields).contains(RelOptUtil.InputFinder.bits(rexNode));
+  }
+
+  private static boolean isRightInputRef(final RexNode rexNode, final int 
numLeftFields)
+  {
+    return rexNode.isA(SqlKind.INPUT_REF) && ((RexInputRef) 
rexNode).getIndex() >= numLeftFields;
+  }
+
+  @VisibleForTesting
+  static class ConditionAnalysis
+  {
+    /**
+     * Number of fields on the left-hand side. Useful for identifying if a 
particular field is from on the left
+     * or right side of a join.
+     */
+    private final int numLeftFields;
+
+    /**
+     * Each equality subcondition is an equality of the form f(LeftRel) = 
g(RightRel).
+     */
+    private final List<Pair<RexNode, RexInputRef>> equalitySubConditions;
+
+    /**
+     * Each literal subcondition is... a literal.
+     */
+    private final List<RexLiteral> literalSubConditions;
+
+    ConditionAnalysis(
+        int numLeftFields,
+        List<Pair<RexNode, RexInputRef>> equalitySubConditions,
+        List<RexLiteral> literalSubConditions
+    )
+    {
+      this.numLeftFields = numLeftFields;
+      this.equalitySubConditions = equalitySubConditions;
+      this.literalSubConditions = literalSubConditions;
+    }
+
+    public ConditionAnalysis pushThroughLeftProject(final Project leftProject)
+    {
+      // Pushing through the project will shift right-hand field references by 
this amount.
+      final int rhsShift =
+          leftProject.getInput().getRowType().getFieldCount() - 
leftProject.getRowType().getFieldCount();
+
+      return new ConditionAnalysis(
+          leftProject.getInput().getRowType().getFieldCount(),
+          equalitySubConditions
+              .stream()
 
 Review comment:
   I can't think of any specific examples off the top of my head, but I know 
we've seen a handful of performance issues using `.stream()`; I don't think 
anything needs to change right now, just commenting to increase the chances 
I'll remember this area as much as anything else as a potential area to look at 
to make small gains in planning time in the future. 
   
   I don't imagine these collections will be so large, so maybe isn't a very 
big deal, but then again could maybe add up depending how planning goes and how 
many times this stuff gets evaluated. 

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

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

Reply via email to