gortiz commented on code in PR #20092:
URL: https://github.com/apache/pinot/pull/20092#discussion_r4630384712
##########
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:
Good point, the constant pass had no alias coverage. Added
testConstantBindsTheTableColumnBehindAnAlias in dbfcda9d09. The dimension side
aliases `currency AS rate`, the condition is `dim.rate = 'gbp' AND
dim.rate_start_date = fact.rate_start_date`, and the test checks that the
currency key position takes the constant and the rate_start_date position takes
the fact column. With the output names instead of the table columns, the test
fails because the condition leaves `currency` open.
--
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]