Hi, Jacques Yes, I'm referring to the RelNode's row type, the planBefore and planAfter's row types are different in field name. I'm trying to convert the optimized RelNodes tree to a sql with same semantics with the original RelNodes, If the field name is missing, the sql will be incorrect.
Thanks JiaTao and Jing, I understand the fact that alias is trivial in rules, But how can Calcite ensure the physical plan which transformed from optimized logical plan outputs the correct column names? Jing Zhang <[email protected]> 于2021年11月26日周五 下午12:46写道: > Hi, > There was a Calcite JIRA (CALCITE-2718 > <https://issues.apache.org/jira/browse/CALCITE-2718>) which describes this > issue exactly. > There are also some other rules which would miss alias, so it's safe to > reference fields by position instead of name. > Hope it helps. > > [1] https://issues.apache.org/jira/browse/CALCITE-2718 > > Best, > Jing Zhang > > JiaTao Tao <[email protected]> 于2021年11月26日周五 上午11:03写道: > > > In fact, calcite's rule doesn't care about alias, so it may lose alias > when > > transforming. > > > > Regards! > > > > Aron Tao > > > > > > Yanjing Wang <[email protected]> 于2021年11月24日周三 下午2:47写道: > > > > > Hi, team > > > I'm using ProjectRemoveRule to simplify my logical plan, But the plan > > > sometimes miss its project alias, I find the rule hasn't checked the > > alias > > > for project row type identity equation, so I think it may be a bug, I > > have > > > tried to reproduce the problem, but I failed to build two projects. > > > > > > I have tried the following but the plan always ignores the alias: > > > > > > final Function<RelBuilder, RelNode> relFn = b -> { > > > RelNode plan = b.scan("EMP") > > > .project( > > > b.field("DEPTNO"), > > > b.field("ENAME") > > > ) > > > .project( > > > b.alias(b.field(0), "DEPTNO_ALIAS"), > > > b.alias(b.field(1), "ENAME_ALIAS") > > > ) > > > .build(); > > > return plan; > > > }; > > > > > > relFn(relFn) > > > .withRule( > > > CoreRules.PROJECT_REMOVE) > > > .withRelBuilderConfig(b -> b.withBloat(-1)) > > > .check(); > > > > > > > > > So I resort to modifying existing test case to reproduce, I change > > > the testUnionMergeRule test case in RelOptRulesTest.java. I change its > > > final projection *** to *name as ename, deptno as edeptno*, > > > and the plan miss the alias again. I think the hep rules shouldn't > remove > > > the alias which are output column label. > > > > > >
