You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "xzh_dz (Jira)" <ji...@apache.org> on 2021/09/26 01:54:00 UTC
[jira] [Created] (CALCITE-4803) RelNode lost alias after remove
Project operator
xzh_dz created CALCITE-4803:
-------------------------------
Summary: RelNode lost alias after remove Project operator
Key: CALCITE-4803
URL: https://issues.apache.org/jira/browse/CALCITE-4803
Project: Calcite
Issue Type: Improvement
Reporter: xzh_dz
In my project, I often use `RelOptRule` to optimize relational algebra. In the process of materialized view optimization, after removing the `Project operator`, I found that RelNode lost its alias and their relational algebra is not equivalent.Examples can be reproduced as follows.
{code:java}
// code placeholder
org.apache.calcite.test.SqlToRelConverterTest
@Test void testLoseAlias() {
final String sql = "select ename as e, deptno as d, count(distinct empno) from emp group by ename, deptno";
final RelNode rel = tester.convertSqlToRel(sql).rel;
// LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT(DISTINCT $2)])
// LogicalProject(E=[$1], D=[$7], EMPNO=[$0])
// LogicalTableScan(table=[[CATALOG, SALES, EMP]])
System.out.println(RelOptUtil.toString(rel));
final HepProgramBuilder programBuilder = HepProgram.builder();
programBuilder.addRuleInstance(CoreRules.AGGREGATE_PROJECT_MERGE);
final HepPlanner planner = new HepPlanner(programBuilder.build());
planner.setRoot(rel);
final RelNode relOpt = planner.findBestExp();
//LogicalAggregate(group=[{1, 7}], EXPR$2=[COUNT(DISTINCT $0)])
// LogicalTableScan(table=[[CATALOG, SALES, EMP]])
System.out.println(RelOptUtil.toString(relOpt));
// [ENAME, DEPTNO, EXPR$2]
System.out.println(relOpt.getRowType().getFieldNames());
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)