suibianwanwan created CALCITE-6744:
--------------------------------------
Summary: Support getColumnOrigins for correlate in
RelMdColumnOrigins
Key: CALCITE-6744
URL: https://issues.apache.org/jira/browse/CALCITE-6744
Project: Calcite
Issue Type: Improvement
Reporter: suibianwanwan
The Correlate is not currently supported when metadata gets the column
origin.(RelMdColumnOrigins#getColumnOrigins)
The following case gets the columnOrigin of the max field on the right side of
Correlate, which actually consists of two fields, but currently only returns
one field.
{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}
Also, if you get columnOrigin on Correlate it will return null.
{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)
.returnNull();
}{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)