[
https://issues.apache.org/jira/browse/CALCITE-6744?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
suibianwanwan updated CALCITE-6744:
-----------------------------------
Description:
The Correlate is not currently supported when metadata gets the column
origin.(RelMdColumnOrigins#getColumnOrigins)
If a column is processed from a correlation variable, the correlation variable
is ignored and the rest of the columns are returned.
In fact, we should return null for cases that cannot be determined.
{code:java}
@Test void testColumnOriginsForCorrelate() {
final String sql = "select (select max(dept.name || '_' || emp.ename)"
+ "from dept where emp.deptno = dept.deptno) from emp";
final RelMetadataFixture fixture = sql(sql);
final HepProgramBuilder programBuilder = HepProgram.builder();
programBuilder.addRuleInstance(CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE);
final HepPlanner planner = new HepPlanner(programBuilder.build());
planner.setRoot(fixture.toRel());
final RelNode optimizedRel = planner.findBestExp();
fixture.withRelTransform(a -> optimizedRel.getInput(0).getInput(1))
.assertColumnOriginSingle("DEPT", "NAME", true);
} {code}
OptimizeRel:
{code:java}
LogicalProject(EXPR$0=[$9])
LogicalCorrelate(correlation=[$cor1], joinType=[left], requiredColumns=[{1,
7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
LogicalProject($f0=[||(||($1, '_'), $cor1.ENAME)])
LogicalFilter(condition=[=($cor1.DEPTNO, $0)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]]){code}
was:
The Correlate is not currently supported when metadata gets the column
origin.(RelMdColumnOrigins#getColumnOrigins)
If a column is processed from a correlation variable, the correlation variable
is ignored in getColumnOrigin.
{code:java}
@Test void testColumnOriginsForCorrelate() {
final String sql = "select (select max(dept.name || '_' || emp.ename)"
+ "from dept where emp.deptno = dept.deptno) from emp";
final RelMetadataFixture fixture = sql(sql);
final HepProgramBuilder programBuilder = HepProgram.builder();
programBuilder.addRuleInstance(CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE);
final HepPlanner planner = new HepPlanner(programBuilder.build());
planner.setRoot(fixture.toRel());
final RelNode optimizedRel = planner.findBestExp();
fixture.withRelTransform(a -> optimizedRel.getInput(0).getInput(1))
.assertColumnOriginSingle("DEPT", "NAME", true);
} {code}
OptimizeRel:
{code:java}
LogicalProject(EXPR$0=[$9])
LogicalCorrelate(correlation=[$cor1], joinType=[left], requiredColumns=[{1,
7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
LogicalProject($f0=[||(||($1, '_'), $cor1.ENAME)])
LogicalFilter(condition=[=($cor1.DEPTNO, $0)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]]){code}
> Returns null when the column origin contains the correlation variable
> ---------------------------------------------------------------------
>
> Key: CALCITE-6744
> URL: https://issues.apache.org/jira/browse/CALCITE-6744
> Project: Calcite
> Issue Type: Improvement
> Reporter: suibianwanwan
> Assignee: suibianwanwan
> Priority: Critical
> Labels: pull-request-available
>
> The Correlate is not currently supported when metadata gets the column
> origin.(RelMdColumnOrigins#getColumnOrigins)
> If a column is processed from a correlation variable, the correlation
> variable is ignored and the rest of the columns are returned.
> In fact, we should return null for cases that cannot be determined.
> {code:java}
> @Test void testColumnOriginsForCorrelate() {
> final String sql = "select (select max(dept.name || '_' || emp.ename)"
> + "from dept where emp.deptno = dept.deptno) from emp";
> final RelMetadataFixture fixture = sql(sql);
> final HepProgramBuilder programBuilder = HepProgram.builder();
> programBuilder.addRuleInstance(CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE);
> final HepPlanner planner = new HepPlanner(programBuilder.build());
> planner.setRoot(fixture.toRel());
> final RelNode optimizedRel = planner.findBestExp();
> fixture.withRelTransform(a -> optimizedRel.getInput(0).getInput(1))
> .assertColumnOriginSingle("DEPT", "NAME", true);
> } {code}
> OptimizeRel:
> {code:java}
> LogicalProject(EXPR$0=[$9])
> LogicalCorrelate(correlation=[$cor1], joinType=[left], requiredColumns=[{1,
> 7}])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
> LogicalProject($f0=[||(||($1, '_'), $cor1.ENAME)])
> LogicalFilter(condition=[=($cor1.DEPTNO, $0)])
> LogicalTableScan(table=[[CATALOG, SALES, DEPT]]){code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)