You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Chunwei Lei (Jira)" <ji...@apache.org> on 2021/11/02 02:07:00 UTC

[jira] [Commented] (CALCITE-4803) RelNode lost alias after remove Project operator

    [ https://issues.apache.org/jira/browse/CALCITE-4803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17437094#comment-17437094 ] 

Chunwei Lei commented on CALCITE-4803:
--------------------------------------

I think the field names are very important, especially for the adhoc query. We should not lose them. In our system, we add a new RelNode called AdhokSink to keep the alias for the adhoc query.

> 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
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
>  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)