gortiz commented on code in PR #13966:
URL: https://github.com/apache/pinot/pull/13966#discussion_r1751609385


##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotJoinExchangeNodeInsertRule.java:
##########
@@ -56,27 +63,49 @@ public boolean matches(RelOptRuleCall call) {
   @Override
   public void onMatch(RelOptRuleCall call) {
     Join join = call.rel(0);
-    RelNode leftInput = join.getInput(0);
-    RelNode rightInput = join.getInput(1);
-
-    RelNode leftExchange;
-    RelNode rightExchange;
+    RelNode leftInput = PinotRuleUtils.unboxRel(join.getInput(0));
+    RelNode rightInput = PinotRuleUtils.unboxRel(join.getInput(1));
     JoinInfo joinInfo = join.analyzeCondition();
+    String joinStrategy = 
PinotHintStrategyTable.getHintOption(join.getHints(), 
PinotHintOptions.JOIN_HINT_OPTIONS,
+        PinotHintOptions.JoinHintOptions.JOIN_STRATEGY);
 
-    if (joinInfo.leftKeys.isEmpty()) {
-      // when there's no JOIN key, use broadcast.
-      leftExchange = PinotLogicalExchange.create(leftInput, 
RelDistributions.RANDOM_DISTRIBUTED);
-      rightExchange = PinotLogicalExchange.create(rightInput, 
RelDistributions.BROADCAST_DISTRIBUTED);
+    RelNode newLeftInput;
+    RelNode newRightInput;
+    if 
(PinotHintOptions.JoinHintOptions.LOOKUP_JOIN_STRATEGY.equals(joinStrategy)) {
+      // Lookup join
+      Preconditions.checkArgument(!joinInfo.leftKeys.isEmpty(), "Lookup join 
requires join keys");
+      newLeftInput = PinotLogicalExchange.create(leftInput, 
RelDistributions.hash(joinInfo.leftKeys));
+      // Right table should be a dimension table, and the right input should 
be an identifier only ProjectNode over
+      // TableScanNode.
+      Preconditions.checkState(rightInput instanceof Project, "Right input for 
lookup join must be a Project, got: %s",
+          rightInput.getClass().getSimpleName());
+      Project project = (Project) rightInput;
+      for (RexNode node : project.getProjects()) {
+        Preconditions.checkState(node instanceof RexInputRef,
+            "Right input for lookup join must be an identifier (RexInputRef) 
only Project, got: %s in project",
+            node.getClass().getSimpleName());
+      }
+      RelNode projectInput = PinotRuleUtils.unboxRel(project.getInput());
+      Preconditions.checkState(projectInput instanceof TableScan,
+          "Right input for lookup join must be a Project over TableScan, got 
Project over: %s",
+          projectInput.getClass().getSimpleName());
+      newRightInput = rightInput;

Review Comment:
   Maybe not needed for this PR, but in the future I think we should need to 
start moving logic to new rules. For example, we can have a rule that only 
applies when the hint is enabled and the right hand side is a project and 
(...all conditions). If the rule applies, we change the node to a DimJoin + 
exchanges.
   



-- 
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...@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to