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

Julian Hyde commented on CALCITE-3922:
--------------------------------------

Ah. Those "{{// Let ProjectRemoveRule handle this}}" comments in 
{{ProjectMergeRule}} make sense except when we are counting on 
{{ProjectMergeRule}} to retain column names. I could imagine adding a mode to 
{{ProjectMergeRule}} where it strives to retain column names (not all the time, 
but any time that it creates a new {{RelNode}}, which is most of the time). In 
that mode, if would not punt when it reaches the two or three occurrences of 
that comment. Maybe we already have that mode, and this should be the behavior 
if {{ProjectMergeRule.force}} is true.

> 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)

Reply via email to