jnaous commented on a change in pull request #9111: Add HashJoinSegment, a 
virtual segment for joins.
URL: https://github.com/apache/druid/pull/9111#discussion_r365328746
 
 

 ##########
 File path: 
processing/src/main/java/org/apache/druid/segment/join/JoinConditionAnalysis.java
 ##########
 @@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.segment.join;
+
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.math.expr.Expr;
+import org.apache.druid.math.expr.ExprMacroTable;
+import org.apache.druid.math.expr.Exprs;
+import org.apache.druid.math.expr.Parser;
+import org.apache.druid.query.expression.ExprUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * Represents analysis of a join condition.
+ *
+ * Each condition is decomposed into "equiConditions" and "nonEquiConditions".
+ *
+ * 1) The equiConditions are of the form ExpressionOfLeft = ColumnFromRight. 
The right-hand part cannot be an expression
+ * because we use this analysis to determine if we can perform the join using 
hashtables built off right-hand-side
+ * columns.
+ *
+ * 2) The nonEquiConditions are other conditions that should also be ANDed 
together
+ *
+ * All of these conditions are ANDed together to get the overall condition.
+ */
+public class JoinConditionAnalysis
+{
+  private final String originalExpression;
+  private final List<Equality> equiConditions;
+  private final List<Expr> nonEquiConditions;
+
+  private JoinConditionAnalysis(
+      final String originalExpression,
+      final List<Equality> equiConditions,
+      final List<Expr> nonEquiConditions
+  )
+  {
+    this.originalExpression = originalExpression;
+    this.equiConditions = equiConditions;
+    this.nonEquiConditions = nonEquiConditions;
+  }
+
+  public static JoinConditionAnalysis forExpression(
+      final String condition,
+      final String rightPrefix,
+      final ExprMacroTable macroTable
+  )
+  {
+    final Expr conditionExpr = Parser.parse(condition, macroTable);
+    final List<Equality> equiConditions = new ArrayList<>();
+    final List<Expr> nonEquiConditions = new ArrayList<>();
+
+    final List<Expr> exprs = Exprs.decomposeAnd(conditionExpr);
+    for (Expr childExpr : exprs) {
+      final Optional<Pair<Expr, Expr>> maybeDecomposed = 
Exprs.decomposeEquals(childExpr);
+
+      if (!maybeDecomposed.isPresent()) {
+        nonEquiConditions.add(childExpr);
+      } else {
+        final Pair<Expr, Expr> decomposed = maybeDecomposed.get();
+        final Expr lhs = decomposed.lhs;
+        final Expr rhs = decomposed.rhs;
+
+        if (isLeftExprAndRightColumn(lhs, rhs, rightPrefix)) {
+          // rhs is a right-hand column; lhs is an expression solely of the 
left-hand side.
+          equiConditions.add(new Equality(lhs, 
rhs.getIdentifierIfIdentifier().substring(rightPrefix.length())));
 
 Review comment:
   Am I correct in understanding that this is doing the `unprefix` method? 
Seems like you should be calling that instead?

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