Jackie-Jiang commented on code in PR #19197:
URL: https://github.com/apache/pinot/pull/19197#discussion_r3752529425


##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/LookupJoinOperator.java:
##########
@@ -96,11 +103,72 @@ public LookupJoinOperator(OpChainExecutionContext context, 
MultiStageOperator le
     _rightColumns = _rightInput.getDataSchema().getColumnNames();
     _resultSchema = node.getDataSchema();
     _resultColumnSize = _resultSchema.size();
+    List<Integer> rightKeys = node.getRightKeys();
+    _rightKeyIds = new int[rightKeys.size()];
+    for (int i = 0; i < rightKeys.size(); i++) {
+      _rightKeyIds[i] = rightKeys.get(i);
+    }
     List<RexExpression> nonEquiConditions = node.getNonEquiConditions();
     _nonEquiEvaluators = new ArrayList<>(nonEquiConditions.size());
     for (RexExpression nonEquiCondition : nonEquiConditions) {
       
_nonEquiEvaluators.add(TransformOperandFactory.getTransformOperand(nonEquiCondition,
 _resultSchema));
     }
+
+    // Build a complete lookup key in the dimension table's primary key column 
order. When a join
+    // condition supplies a dimension primary key component as a literal (e.g. 
"dim_tbl.currency = 'gbp'"),
+    // Calcite's analyzeCondition() classifies it as a non-equi condition 
rather than an equi-join key, so it
+    // is absent from leftKeys/rightKeys. The lookup key must still include 
that component, otherwise the
+    // lookup misses and returns 0 rows. Fill each primary key position from 
either the corresponding left
+    // column (equi-join) or the literal value (non-equi condition).
+    List<String> primaryKeyColumns = _rightTable.getPrimaryKeyColumns();
+    Preconditions.checkState(primaryKeyColumns != null && 
!primaryKeyColumns.isEmpty(),
+        "Dimension table must have primary key columns for lookup join");
+    _keyLeftIndices = new int[primaryKeyColumns.size()];
+    _keyLiteralValues = new Object[primaryKeyColumns.size()];
+    Arrays.fill(_keyLeftIndices, -1);
+
+    // Map equi-join right keys to their primary key column positions.
+    for (int i = 0; i < rightKeys.size(); i++) {
+      String rightColumnName = _rightColumns[rightKeys.get(i)];
+      int pkPosition = primaryKeyColumns.indexOf(rightColumnName);
+      if (pkPosition >= 0) {
+        _keyLeftIndices[pkPosition] = leftKeys.get(i);
+      }
+    }
+
+    // Extract literal values for primary key components supplied as literals 
in non-equi conditions of the
+    // form "dimension_column = literal" (or "literal = dimension_column").
+    for (RexExpression nonEquiCondition : nonEquiConditions) {
+      if (nonEquiCondition instanceof RexExpression.FunctionCall) {
+        RexExpression.FunctionCall functionCall = (RexExpression.FunctionCall) 
nonEquiCondition;
+        if ("EQUALS".equals(functionCall.getFunctionName()) && 
functionCall.getFunctionOperands().size() == 2) {

Review Comment:
   This is not general enough. Essentially we want to support extra filters on 
looked-up records, and it is not limited to `EQUALS`



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