Class PushProjector

java.lang.Object
org.apache.calcite.rel.rules.PushProjector

public class PushProjector extends Object
PushProjector is a utility class used to perform operations used in push projection rules.

Pushing is particularly interesting in the case of join, because there are multiple inputs. Generally an expression can be pushed down to a particular input if it depends upon no other inputs. If it can be pushed down to both sides, it is pushed down to the left.

Sometimes an expression needs to be split before it can be pushed down. To flag that an expression cannot be split, specify a rule that it must be preserved. Such an expression will be pushed down intact to one of the inputs, or not pushed down at all.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    A functor that replies true or false for a given expression.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PushProjector(@Nullable Project origProj, @Nullable RexNode origFilter, RelNode childRel, PushProjector.ExprCondition preserveExprCondition, RelBuilder relBuilder)
    Creates a PushProjector object for pushing projects past a RelNode.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable RelNode
    convertProject(@Nullable RexNode defaultExpr)
    Decomposes a projection to the input references referenced by a projection and a filter, either of which is optional.
    convertRefsAndExprs(RexNode rex, List<RelDataTypeField> destFields, int[] adjustments)
    Clones an expression tree and walks through it, adjusting each RexInputRef index by some amount, and converting expressions that need to be preserved to field references.
    createNewProject(RelNode projChild, int[] adjustments)
    Creates a new projection based on the original projection, adjusting all input refs using an adjustment array passed in.
    createProjectRefsAndExprs(RelNode projChild, boolean adjust, boolean rightSide)
    Creates a projection based on the inputs specified in a bitmap and the expressions that need to be preserved.
    int[]
    Determines how much each input reference needs to be adjusted as a result of projection.
    boolean
    Locates all references found in either the projection expressions a filter, as well as references to expressions that should be preserved.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PushProjector

      public PushProjector(@Nullable Project origProj, @Nullable RexNode origFilter, RelNode childRel, PushProjector.ExprCondition preserveExprCondition, RelBuilder relBuilder)
      Creates a PushProjector object for pushing projects past a RelNode.
      Parameters:
      origProj - the original projection that is being pushed; may be null if the projection is implied as a result of a projection having been trivially removed
      origFilter - the filter that the projection must also be pushed past, if applicable
      childRel - the RelNode that the projection is being pushed past
      preserveExprCondition - condition for whether an expression should be preserved in the projection
  • Method Details

    • convertProject

      public @Nullable RelNode convertProject(@Nullable RexNode defaultExpr)
      Decomposes a projection to the input references referenced by a projection and a filter, either of which is optional. If both are provided, the filter is underneath the project.

      Creates a projection containing all input references as well as preserving any special expressions. Converts the original projection and/or filter to reference the new projection. Then, finally puts on top, a final projection corresponding to the original projection.

      Parameters:
      defaultExpr - expression to be used in the projection if no fields or special columns are selected
      Returns:
      the converted projection if it makes sense to push elements of the projection; otherwise returns null
    • locateAllRefs

      public boolean locateAllRefs()
      Locates all references found in either the projection expressions a filter, as well as references to expressions that should be preserved. Based on that, determines whether pushing the projection makes sense.
      Returns:
      true if all inputs from the child that the projection is being pushed past are referenced in the projection/filter and no special preserve expressions are referenced; in that case, it does not make sense to push the projection
    • createProjectRefsAndExprs

      public Project createProjectRefsAndExprs(RelNode projChild, boolean adjust, boolean rightSide)
      Creates a projection based on the inputs specified in a bitmap and the expressions that need to be preserved. The expressions are appended after the input references.
      Parameters:
      projChild - child that the projection will be created on top of
      adjust - if true, need to create new projection expressions; otherwise, the existing ones are reused
      rightSide - if true, creating a projection for the right hand side of a join
      Returns:
      created projection
    • getAdjustments

      public int[] getAdjustments()
      Determines how much each input reference needs to be adjusted as a result of projection.
      Returns:
      array indicating how much each input needs to be adjusted by
    • convertRefsAndExprs

      public RexNode convertRefsAndExprs(RexNode rex, List<RelDataTypeField> destFields, int[] adjustments)
      Clones an expression tree and walks through it, adjusting each RexInputRef index by some amount, and converting expressions that need to be preserved to field references.
      Parameters:
      rex - the expression
      destFields - fields that the new expressions will be referencing
      adjustments - the amount each input reference index needs to be adjusted by
      Returns:
      modified expression tree
    • createNewProject

      public RelNode createNewProject(RelNode projChild, int[] adjustments)
      Creates a new projection based on the original projection, adjusting all input refs using an adjustment array passed in. If there was no original projection, create a new one that selects every field from the underlying rel.

      If the resulting projection would be trivial, return the child.

      Parameters:
      projChild - child of the new project
      adjustments - array indicating how much each input reference should be adjusted by
      Returns:
      the created projection