Class TopNPrel

java.lang.Object
org.apache.calcite.rel.AbstractRelNode
org.apache.calcite.rel.SingleRel
org.apache.drill.exec.planner.physical.SinglePrel
org.apache.drill.exec.planner.physical.TopNPrel
All Implemented Interfaces:
Cloneable, Iterable<Prel>, org.apache.calcite.plan.RelOptNode, org.apache.calcite.rel.RelNode, DrillRelNode, OrderedRel, Prel

public class TopNPrel extends SinglePrel implements OrderedRel, Prel
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.apache.calcite.rel.RelNode

    org.apache.calcite.rel.RelNode.Context
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.apache.calcite.rel.RelCollation
     
    protected int
     

    Fields inherited from class org.apache.calcite.rel.SingleRel

    input

    Fields inherited from class org.apache.calcite.rel.AbstractRelNode

    digest, id, rowType, traitSet

    Fields inherited from interface org.apache.drill.exec.planner.physical.Prel

    DRILL_PHYSICAL
  • Constructor Summary

    Constructors
    Constructor
    Description
    TopNPrel(org.apache.calcite.plan.RelOptCluster cluster, org.apache.calcite.plan.RelTraitSet traitSet, org.apache.calcite.rel.RelNode child, int limit, org.apache.calcite.rel.RelCollation collation)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    A method to return if this relational node can be dropped during optimization process.
    org.apache.calcite.plan.RelOptCost
    computeSelfCost(org.apache.calcite.plan.RelOptPlanner planner, org.apache.calcite.rel.metadata.RelMetadataQuery mq)
    Cost of doing Top-N is proportional to M log N where M is the total number of input rows and N is the limit for Top-N.
    org.apache.calcite.rel.RelNode
    copy(org.apache.calcite.plan.RelTraitSet traitSet, List<org.apache.calcite.rel.RelNode> inputs)
     
    org.apache.calcite.rel.RelWriter
    explainTerms(org.apache.calcite.rel.RelWriter pw)
     
    org.apache.calcite.rel.RelCollation
    A method to return ordering columns of the result.
    A Prel's own SelectionVector mode - i.e whether it generates an SV2, SV4 or None
    org.apache.calcite.rex.RexNode
    Fetch value represented in RexNode.
    int
     
    org.apache.calcite.rex.RexNode
    Offset value represented in RexNode.
     
    Supported 'encodings' of a Prel indicates what are the acceptable modes of SelectionVector of its child Prel
    prepareForLateralUnnestPipeline(List<org.apache.calcite.rel.RelNode> children)
    If the operator is in Lateral/Unnest pipeline, then it generates a new operator which knows how to process the rows accordingly during execution.

    Methods inherited from class org.apache.drill.exec.planner.physical.SinglePrel

    accept, iterator, needsFinalColumnReordering

    Methods inherited from class org.apache.calcite.rel.SingleRel

    childrenAccept, deriveRowType, estimateRowCount, getInput, getInputs, replaceInput

    Methods inherited from class org.apache.calcite.rel.AbstractRelNode

    accept, accept, collectVariablesSet, collectVariablesUsed, deepEquals, deepHashCode, equals, explain, getCluster, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getRelDigest, getRelTypeName, getRowType, getTable, getTraitSet, getVariablesSet, hashCode, isEnforcer, isValid, metadata, onRegister, recomputeDigest, register, sole, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator

    Methods inherited from interface org.apache.drill.exec.planner.physical.Prel

    accept, needsFinalColumnReordering

    Methods inherited from interface org.apache.calcite.rel.RelNode

    accept, accept, childrenAccept, collectVariablesSet, collectVariablesUsed, deepEquals, deepHashCode, estimateRowCount, explain, explain, fieldIsNullable, getConvention, getCorrelVariable, getDigest, getExpectedInputRowType, getInput, getInputs, getRelDigest, getRelTypeName, getRowType, getTable, getVariablesSet, isEnforcer, isValid, metadata, onRegister, recomputeDigest, register, replaceInput

    Methods inherited from interface org.apache.calcite.plan.RelOptNode

    getCluster, getDescription, getId, getTraitSet
  • Field Details

    • limit

      protected int limit
    • collation

      protected final org.apache.calcite.rel.RelCollation collation
  • Constructor Details

    • TopNPrel

      public TopNPrel(org.apache.calcite.plan.RelOptCluster cluster, org.apache.calcite.plan.RelTraitSet traitSet, org.apache.calcite.rel.RelNode child, int limit, org.apache.calcite.rel.RelCollation collation)
  • Method Details

    • copy

      public org.apache.calcite.rel.RelNode copy(org.apache.calcite.plan.RelTraitSet traitSet, List<org.apache.calcite.rel.RelNode> inputs)
      Specified by:
      copy in interface org.apache.calcite.rel.RelNode
      Overrides:
      copy in class org.apache.calcite.rel.AbstractRelNode
    • getPhysicalOperator

      public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException
      Specified by:
      getPhysicalOperator in interface Prel
      Throws:
      IOException
    • getCollation

      public org.apache.calcite.rel.RelCollation getCollation()
      Description copied from interface: OrderedRel
      A method to return ordering columns of the result.
      Specified by:
      getCollation in interface OrderedRel
      Returns:
      Collation order of the output.
    • getOffset

      public org.apache.calcite.rex.RexNode getOffset()
      Description copied from interface: OrderedRel
      Offset value represented in RexNode.
      Specified by:
      getOffset in interface OrderedRel
      Returns:
      offset.
    • getFetch

      public org.apache.calcite.rex.RexNode getFetch()
      Description copied from interface: OrderedRel
      Fetch value represented in RexNode.
      Specified by:
      getFetch in interface OrderedRel
      Returns:
      fetch
    • canBeDropped

      public boolean canBeDropped()
      Description copied from interface: OrderedRel
      A method to return if this relational node can be dropped during optimization process.
      Specified by:
      canBeDropped in interface OrderedRel
      Returns:
      true if this node can be dropped, false otherwise.
    • computeSelfCost

      public org.apache.calcite.plan.RelOptCost computeSelfCost(org.apache.calcite.plan.RelOptPlanner planner, org.apache.calcite.rel.metadata.RelMetadataQuery mq)
      Cost of doing Top-N is proportional to M log N where M is the total number of input rows and N is the limit for Top-N. This makes Top-N preferable to Sort since cost of full Sort is proportional to M log M .
      Specified by:
      computeSelfCost in interface org.apache.calcite.rel.RelNode
      Overrides:
      computeSelfCost in class org.apache.calcite.rel.AbstractRelNode
    • explainTerms

      public org.apache.calcite.rel.RelWriter explainTerms(org.apache.calcite.rel.RelWriter pw)
      Overrides:
      explainTerms in class org.apache.calcite.rel.SingleRel
    • getLimit

      public int getLimit()
    • getSupportedEncodings

      public BatchSchema.SelectionVectorMode[] getSupportedEncodings()
      Description copied from interface: Prel
      Supported 'encodings' of a Prel indicates what are the acceptable modes of SelectionVector of its child Prel
      Specified by:
      getSupportedEncodings in interface Prel
      Overrides:
      getSupportedEncodings in class SinglePrel
    • getEncoding

      public BatchSchema.SelectionVectorMode getEncoding()
      Description copied from interface: Prel
      A Prel's own SelectionVector mode - i.e whether it generates an SV2, SV4 or None
      Specified by:
      getEncoding in interface Prel
    • prepareForLateralUnnestPipeline

      public Prel prepareForLateralUnnestPipeline(List<org.apache.calcite.rel.RelNode> children)
      Description copied from interface: Prel
      If the operator is in Lateral/Unnest pipeline, then it generates a new operator which knows how to process the rows accordingly during execution. eg: TopNPrel -> SortPrel and LimitPrel Other operators like FilterPrel, ProjectPrel etc will add an implicit row id to the output.
      Specified by:
      prepareForLateralUnnestPipeline in interface Prel