-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-7646] CorrelateProjectExtractor does not handle nested field accesses cor0.field0.field1
#5086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[CALCITE-7646] CorrelateProjectExtractor does not handle nested field accesses cor0.field0.field1
#5086
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,78 @@ public static Frameworks.ConfigBuilder config() { | |
| assertThat(after, hasTree(planAfter)); | ||
| } | ||
|
|
||
| /** Test case for <a href="https://issues.apache.org/jira/browse/CALCITE-7646">[CALCITE-7646] | ||
| * CorrelateProjectExtractor does not handle nested field accesses cor0.field0.field1</a>. */ | ||
| @Test void testNestedCorrelationFieldAccessInFilter() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new logic returns null from |
||
| final RelBuilder builder = RelBuilder.create(config().build()); | ||
| final Holder<@Nullable RexCorrelVariable> v = Holder.empty(); | ||
| RelNode before = builder.scan("EMP") | ||
| .project( | ||
| builder.alias( | ||
| builder.call(SqlStdOperatorTable.ROW, | ||
| builder.field("EMPNO"), builder.field("DEPTNO")), "R")) | ||
| .variable(v::set) | ||
| .scan("DEPT") | ||
| .filter( | ||
| builder.equals(builder.field(0), | ||
| builder.getRexBuilder().makeFieldAccess(builder.field(v.get(), "R"), 1))) | ||
| .correlate(JoinRelType.LEFT, v.get().id, builder.field(2, 0, "R")) | ||
| .build(); | ||
|
|
||
| final String planBefore = "" | ||
| + "LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0}])\n" | ||
| + " LogicalProject(R=[ROW($0, $7)])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n" | ||
| + " LogicalFilter(condition=[=($0, $cor0.R.EXPR$1)])\n" | ||
| + " LogicalTableScan(table=[[scott, DEPT]])\n"; | ||
| assertThat(before, hasTree(planBefore)); | ||
|
|
||
| RelNode after = before.accept(new CorrelateProjectExtractor(RelFactories.LOGICAL_BUILDER)); | ||
| final String planAfter = "" | ||
| + "LogicalProject(R=[$0], DEPTNO=[$2], DNAME=[$3], LOC=[$4])\n" | ||
| + " LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{1}])\n" | ||
| + " LogicalProject(R=[ROW($0, $7)], $f1=[ROW($0, $7).EXPR$1])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n" | ||
| + " LogicalFilter(condition=[=($0, $cor0.$f1)])\n" | ||
| + " LogicalTableScan(table=[[scott, DEPT]])\n"; | ||
| assertThat(after, hasTree(planAfter)); | ||
| } | ||
|
|
||
| /** Tests that a constant call operand, such as {@code POWER(2, 3)}, does | ||
| * not prevent extracting the enclosing correlated call. */ | ||
| @Test void testCorrelationCallWithConstantCallOperandInFilter() { | ||
| final RelBuilder builder = RelBuilder.create(config().build()); | ||
| final Holder<@Nullable RexCorrelVariable> v = Holder.empty(); | ||
| RelNode before = builder.scan("EMP") | ||
| .variable(v::set) | ||
| .scan("DEPT") | ||
| .filter( | ||
| builder.equals(builder.field(0), | ||
| builder.call(SqlStdOperatorTable.PLUS, | ||
| builder.call(SqlStdOperatorTable.POWER, | ||
| builder.literal(2), builder.literal(3)), | ||
| builder.field(v.get(), "DEPTNO")))) | ||
| .correlate(JoinRelType.LEFT, v.get().id, builder.field(2, 0, "DEPTNO")) | ||
| .build(); | ||
|
|
||
| final String planBefore = "" | ||
| + "LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n" | ||
| + " LogicalFilter(condition=[=($0, +(POWER(2, 3), $cor0.DEPTNO))])\n" | ||
| + " LogicalTableScan(table=[[scott, DEPT]])\n"; | ||
| assertThat(before, hasTree(planBefore)); | ||
|
|
||
| RelNode after = before.accept(new CorrelateProjectExtractor(RelFactories.LOGICAL_BUILDER)); | ||
| final String planAfter = "" | ||
| + "LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], DEPTNO0=[$9], DNAME=[$10], LOC=[$11])\n" | ||
| + " LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{8}])\n" | ||
| + " LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], $f8=[+(POWER(2, 3), $7)])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n" | ||
| + " LogicalFilter(condition=[=($0, $cor0.$f8)])\n" | ||
| + " LogicalTableScan(table=[[scott, DEPT]])\n"; | ||
| assertThat(after, hasTree(planAfter)); | ||
| } | ||
|
|
||
| @Test void testDoubleCorrelationCallOverVariableInFilters() { | ||
| final RelBuilder builder = RelBuilder.create(config().build()); | ||
| final Holder<@Nullable RexCorrelVariable> v = Holder.empty(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments should be left-aligned.