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


##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/LookupJoinOperatorTest.java:
##########
@@ -208,6 +212,79 @@ public void testMissingPrimaryKeyColumnsAreRejected() {
     assertTrue(exception.getMessage().contains("Failed to find primary key 
columns"), exception.getMessage());
   }
 
+  @Test
+  public void testDimensionColumnsOfTableScan() {
+    assertEquals(LookupJoinOperator.resolveDimensionColumns(tableScan(), 
TABLE_NAME),
+        new String[]{"currency", "rate", "rate_start_date"});
+  }
+
+  @Test
+  public void testDimensionColumnsFollowProjectInputRefsNotOutputNames() {
+    // SELECT currency AS rate, rate AS currency, rate_start_date, 
rate_start_date AS rate_start_date0
+    DataSchema projectSchema =
+        new DataSchema(new String[]{"rate", "currency", "rate_start_date", 
"rate_start_date0"}, new ColumnDataType[]{
+            ColumnDataType.STRING, ColumnDataType.INT, ColumnDataType.LONG, 
ColumnDataType.LONG
+        });
+    ProjectNode project = new ProjectNode(0, projectSchema, 
PlanNode.NodeHint.EMPTY, List.of(tableScan()),
+        List.of(new RexExpression.InputRef(DIM_CURRENCY), new 
RexExpression.InputRef(DIM_RATE),
+            new RexExpression.InputRef(DIM_RATE_START_DATE), new 
RexExpression.InputRef(DIM_RATE_START_DATE)));
+    assertEquals(LookupJoinOperator.resolveDimensionColumns(project, 
TABLE_NAME),
+        new String[]{"currency", "rate", "rate_start_date", 
"rate_start_date"});
+  }
+
+  @Test
+  public void testDimensionColumnsRejectComputedProject() {
+    DataSchema projectSchema = new DataSchema(new String[]{"literal"}, new 
ColumnDataType[]{ColumnDataType.INT});
+    ProjectNode project = new ProjectNode(0, projectSchema, 
PlanNode.NodeHint.EMPTY, List.of(tableScan()),
+        List.of(new RexExpression.Literal(ColumnDataType.INT, 1)));
+    IllegalStateException exception = expectThrows(IllegalStateException.class,
+        () -> LookupJoinOperator.resolveDimensionColumns(project, TABLE_NAME));
+    assertTrue(exception.getMessage().contains("must project columns only"), 
exception.getMessage());
+  }
+
+  @Test
+  public void testDimensionColumnsRejectProjectOverFilter() {
+    FilterNode filter = new FilterNode(0, DIM_SCHEMA, PlanNode.NodeHint.EMPTY, 
List.of(tableScan()),
+        new RexExpression.Literal(ColumnDataType.BOOLEAN, 1));
+    ProjectNode project = new ProjectNode(0, DIM_SCHEMA, 
PlanNode.NodeHint.EMPTY, List.of(filter),
+        List.of(new RexExpression.InputRef(DIM_CURRENCY), new 
RexExpression.InputRef(DIM_RATE),
+            new RexExpression.InputRef(DIM_RATE_START_DATE)));
+    IllegalStateException exception = expectThrows(IllegalStateException.class,
+        () -> LookupJoinOperator.resolveDimensionColumns(project, TABLE_NAME));
+    assertTrue(exception.getMessage().contains("must be a Project over a 
TableScan"), exception.getMessage());
+  }
+
+  @Test
+  public void testKeyBindsTheTableColumnBehindAnAlias() {
+    // SELECT currency AS rate, rate AS currency, rate_start_date FROM 
dim_tbl, joined
+    // ON dim.rate = fact.currency AND dim.rate_start_date = 
fact.rate_start_date. The output name "rate" is the table
+    // column "currency", so matching output names against the primary key 
would reject the condition.
+    DataSchema aliasedSchema = new DataSchema(new String[]{"rate", "currency", 
"rate_start_date"},
+        new ColumnDataType[]{ColumnDataType.STRING, ColumnDataType.INT, 
ColumnDataType.LONG});
+    JoinNode node = new JoinNode(0, aliasedSchema, PlanNode.NodeHint.EMPTY, 
List.of(), JoinRelType.INNER,
+        List.of(FACT_CURRENCY, FACT_RATE_START_DATE), List.of(0, 2), 
List.of(), JoinNode.JoinStrategy.LOOKUP);
+    LookupJoinOperator.KeyPlan keyPlan = 
LookupJoinOperator.compileKeyPlan(node, TABLE_NAME, PRIMARY_KEY_COLUMNS,
+        aliasedSchema, DIM_SCHEMA.getColumnNames(), LEFT_COLUMN_SIZE);

Review Comment:
   Non-blocking: an additional alias case where one component of a composite 
primary key is bound by a literal would cover the second pass in 
`compileKeyPlan`. This test exercises aliases for equi-join keys; the 
constant-binding pass also changed from output names to physical names. For 
example, bind aliased `currency` to `'gbp'` and join `rate_start_date` to the 
fact column, then assert both key sources.



##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/LookupJoinOperatorTest.java:
##########
@@ -208,6 +212,79 @@ public void testMissingPrimaryKeyColumnsAreRejected() {
     assertTrue(exception.getMessage().contains("Failed to find primary key 
columns"), exception.getMessage());
   }
 
+  @Test
+  public void testDimensionColumnsOfTableScan() {
+    assertEquals(LookupJoinOperator.resolveDimensionColumns(tableScan(), 
TABLE_NAME),
+        new String[]{"currency", "rate", "rate_start_date"});
+  }
+
+  @Test
+  public void testDimensionColumnsFollowProjectInputRefsNotOutputNames() {
+    // SELECT currency AS rate, rate AS currency, rate_start_date, 
rate_start_date AS rate_start_date0
+    DataSchema projectSchema =
+        new DataSchema(new String[]{"rate", "currency", "rate_start_date", 
"rate_start_date0"}, new ColumnDataType[]{
+            ColumnDataType.STRING, ColumnDataType.INT, ColumnDataType.LONG, 
ColumnDataType.LONG
+        });
+    ProjectNode project = new ProjectNode(0, projectSchema, 
PlanNode.NodeHint.EMPTY, List.of(tableScan()),
+        List.of(new RexExpression.InputRef(DIM_CURRENCY), new 
RexExpression.InputRef(DIM_RATE),
+            new RexExpression.InputRef(DIM_RATE_START_DATE), new 
RexExpression.InputRef(DIM_RATE_START_DATE)));

Review Comment:
   Non-blocking: consider making this projection reorder and prune the scan 
columns as well as repeat one, e.g. input refs `[2, 0, 2]` with matching output 
types. The current `[0, 1, 2, 2]` covers aliases and repetition, but an 
explicit permutation would more directly protect the 
output-position-to-physical-column mapping.



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