Class Correlate

All Implemented Interfaces:
Cloneable, RelOptNode, Hintable, RelNode
Direct Known Subclasses:
EnumerableCorrelate, LogicalCorrelate, SqlToRelTestBase.CustomCorrelate

public abstract class Correlate extends BiRel implements Hintable
A relational operator that performs nested-loop joins.

It behaves like a kind of Join, but works by setting variables in its environment and restarting its right-hand input.

Correlate is not a join since: typical rules should not match Correlate.

A Correlate is used to represent a correlated query. One implementation strategy is to de-correlate the expression.

Mapping of physical operations to logical ones
Physical operationLogical operation
NestedLoopsCorrelate(A, B, regular)
NestedLoopsOuterCorrelate(A, B, outer)
NestedLoopsSemiCorrelate(A, B, semi)
NestedLoopsAntiCorrelate(A, B, anti)
HashJoinEquiJoin(A, B)
HashJoinOuterEquiJoin(A, B, outer)
HashJoinSemiSemiJoin(A, B, semi)
HashJoinAntiSemiJoin(A, B, anti)
See Also:
  • Field Details

    • correlationId

      protected final CorrelationId correlationId
    • requiredColumns

      protected final ImmutableBitSet requiredColumns
    • joinType

      protected final JoinRelType joinType
    • hints

      protected final<RelHint> hints
  • Constructor Details

  • Method Details

    • isValid

      public boolean isValid(Litmus litmus, @Nullable RelNode.Context context)
      Description copied from interface: RelNode
      Returns whether this relational expression is valid.

      If assertions are enabled, this method is typically called with litmus = THROW, as follows:

      assert rel.isValid(Litmus.THROW)

      This signals that the method can throw an AssertionError if it is not valid.

      Specified by:
      isValid in interface RelNode
      isValid in class AbstractRelNode
      litmus - What to do if invalid
      context - Context for validity checking
      Whether relational expression is valid
    • copy

      public Correlate copy(RelTraitSet traitSet, List<RelNode> inputs)
      Description copied from interface: RelNode
      Creates a copy of this relational expression, perhaps changing traits and inputs.

      Sub-classes with other important attributes are encouraged to create variants of this method with more parameters.

      Specified by:
      copy in interface RelNode
      copy in class AbstractRelNode
      traitSet - Trait set
      inputs - Inputs
      Copy of this relational expression, substituting traits and inputs
    • copy

      public abstract Correlate copy(RelTraitSet traitSet, RelNode left, RelNode right, CorrelationId correlationId, ImmutableBitSet requiredColumns, JoinRelType joinType)
    • getJoinType

      public JoinRelType getJoinType()
    • deriveRowType

      protected RelDataType deriveRowType()
      deriveRowType in class AbstractRelNode
    • explainTerms

      public RelWriter explainTerms(RelWriter pw)
      Description copied from class: AbstractRelNode
      Describes the inputs and attributes of this relational expression. Each node should call super.explainTerms, then call the RelWriter.input(String, RelNode) and RelWriter.item(String, Object) methods for each input and attribute.
      explainTerms in class BiRel
      pw - Plan writer
      Plan writer for fluent-explain pattern
    • getCorrelationId

      public CorrelationId getCorrelationId()
      Returns the correlating expressions.
      correlating expressions
    • getCorrelVariable

      public String getCorrelVariable()
      Description copied from interface: RelNode
      Returns the name of the variable which is to be implicitly set at runtime each time a row is returned from the first input of this relational expression; or null if there is no variable.
      Specified by:
      getCorrelVariable in interface RelNode
      getCorrelVariable in class AbstractRelNode
      Name of correlating variable, or null
    • getRequiredColumns

      public ImmutableBitSet getRequiredColumns()
      Returns the required columns in left relation required for the correlation in the right.
      columns in left relation required for the correlation in the right
    • getVariablesSet

      public Set<CorrelationId> getVariablesSet()
      Description copied from interface: RelNode
      Returns the variables that are set in this relational expression but also used and therefore not available to parents of this relational expression.
      Specified by:
      getVariablesSet in interface RelNode
      getVariablesSet in class AbstractRelNode
      Names of variables which are set in this relational expression
    • estimateRowCount

      public double estimateRowCount(RelMetadataQuery mq)
      Description copied from interface: RelNode
      Returns an estimate of the number of rows this relational expression will return.

      NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getRowCount(org.apache.calcite.rel.RelNode), which gives plugins a chance to override the rel's default ideas about row count.

      Specified by:
      estimateRowCount in interface RelNode
      estimateRowCount in class AbstractRelNode
      mq - Metadata query
      Estimate of the number of rows this relational expression will return
    • computeSelfCost

      public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
      Description copied from interface: RelNode
      Returns the cost of this plan (not including children). The base implementation throws an error; derived classes should override.

      NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getNonCumulativeCost(org.apache.calcite.rel.RelNode), which gives plugins a chance to override the rel's default ideas about cost.

      Specified by:
      computeSelfCost in interface RelNode
      computeSelfCost in class AbstractRelNode
      planner - Planner for cost calculation
      mq - Metadata query
      Cost of this plan (not including children)
    • getHints

      public<RelHint> getHints()
      Description copied from interface: Hintable
      Returns the hints of this relational expressions as an immutable list.
      Specified by:
      getHints in interface Hintable