[
https://issues.apache.org/jira/browse/CALCITE-3922?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17083514#comment-17083514
]
Steven Talbot commented on CALCITE-3922:
----------------------------------------
Good point. I should probably just rename the result of the planner to what I
put into it. I do that elsewhere and just sort of spaced out here. And, in
terms of ProjectMergeRule, that's actually where I started but it's got
[https://github.com/apache/calcite/blob/f1857aa305c99dca40ee3c940ee689d77f27eaee/core/src/main/java/org/apache/calcite/rel/rules/ProjectMergeRule.java#L94]
to explicitly skip this case in favor of ProjectRemoveRule, for some reason.
> ProjectRemoveRule drops aliases when used with HepPlanner
> ---------------------------------------------------------
>
> Key: CALCITE-3922
> URL: https://issues.apache.org/jira/browse/CALCITE-3922
> Project: Calcite
> Issue Type: Bug
> Reporter: Steven Talbot
> Priority: Major
>
> The line at
> [https://github.com/apache/calcite/blob/15fa9bc67a8ed12ec6b8e0d1dbced8760ae307ab/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java#L67]
> checks for the input being an instanceof Project, but in the HepPlanner
> every input is always a HepRelVertex.
>
> I struggled writing a test for this, but I finally got one (in
> HepPlannerTest). The thing the test does is similar to how I hit this: you
> tend to only have trivial projects on top of other trivial projects if a rule
> moved them around. RelBuilder and SqlToRelConverter will just pre-squash them
> for you.
>
> {code:java}
> @Test public void testProjectRemoveRuleWithAliases() {
> HepProgram prog = HepProgram.builder()
> .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
> .addRuleInstance(ProjectRemoveRule.INSTANCE)
> .build();
> HepPlanner planner = new HepPlanner(prog);
> RelBuilder relBuilder =
> RelBuilder.create(Frameworks.newConfigBuilder().build());
> String[] fieldNames = {"name", "other"};
> relBuilder.values(fieldNames, "something", "something else");
> relBuilder.project(relBuilder.field("name"));
> // add a filter so the projects won't squash together: it will be moved
> below by the transpose rule
> relBuilder.filter(relBuilder.call(SqlStdOperatorTable.LIKE,
> relBuilder.field("name"), relBuilder.literal("something")));
> relBuilder.rename(ImmutableList.of("name1"));
> planner.setRoot(relBuilder.build());
> RelNode opt = planner.findBestExp();
> assertEquals(LogicalValues.class, opt.getInput(0).getInput(0).getClass(),
> "should have removed the project");
> assertEquals("name1", opt.getRowType().getFieldNames().get(0), "should
> have kept the rename");
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)