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

Vladimir Sitnikov edited comment on CALCITE-2582 at 9/21/18 10:42 AM:
----------------------------------------------------------------------

Alternative option is to use the following approach:
{code:java}    RelNode newFilterRel =
        relBuilder.push(project.getInput()).filter(newCondition).build();

    if (newFilterRel instanceof Filter && copyFilter
        && filter.getClass() != newFilterRel.getClass()) {
      Filter x = (Filter) newFilterRel;
      newFilterRel = filter.copy(filter.getTraitSet(), x.getInput(), 
x.getCondition());
    }

    RelNode newProjRel =
        relBuilder.push(newFilterRel)
            .project(project.getProjects(), 
project.getRowType().getFieldNames())
            .build();
    if (newProjRel instanceof Project && copyProject
        && project.getClass() != newProjRel.getClass()) {
      Project x = (Project) newProjRel;
      newProjRel =
          project.copy(project.getTraitSet(), x.getInput(), x.getProjects(), 
x.getRowType());
    }
{code}

The good part with that approach is encapsulates all the smarts into RelBuilder.

[~julianhyde], [~zabetak] what do you think?


was (Author: vladimirsitnikov):
Alternative option is to use the following approach:
{code:java}    final RelBuilder relBuilder = call.builder();
    RelNode newFilterRel =
        relBuilder.push(project.getInput()).filter(newCondition).build();

    if (newFilterRel instanceof Filter && copyFilter) {
      Filter x = (Filter) newFilterRel;
      newFilterRel = filter.copy(filter.getTraitSet(), x.getInput(), 
x.getCondition());
    }

    RelNode newProjRel =
        relBuilder.push(newFilterRel)
            .project(project.getProjects(), 
project.getRowType().getFieldNames())
            .build();
    if (newProjRel instanceof Project && copyProject) {
      Project x = (Project) newProjRel;
      newProjRel =
          project.copy(project.getTraitSet(), x.getInput(), x.getProjects(), 
x.getRowType());
    }

    call.transformTo(newProjRel);
{code}

The good part with that approach is encapsulates all the smarts into RelBuilder.

[~julianhyde], [~zabetak] what do you think?

> FilterProjectTransposeRule does not always simplify the new filter condition
> ----------------------------------------------------------------------------
>
>                 Key: CALCITE-2582
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2582
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.17.0
>            Reporter: Stamatis Zampetakis
>            Assignee: Julian Hyde
>            Priority: Minor
>             Fix For: 1.18.0
>
>
> After pushing the filter below the project a new condition is going to be 
> generated along with a new Filter operator. The new condition is not going to 
> be simplified if the filter operator is copied and not created using the 
> RelBuilder. 
> Thus the resulting plan may contain redundant conditions which can have a 
> slight impact on performance. Apart, from that tests verifying the resulting 
> (logical/physical) plan may produce indeterministic results if the rule is 
> applied with (a different order and in combination with other rules). 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to