Class Sort
- All Implemented Interfaces:
Cloneable,RelOptNode,Hintable,RelNode
- Direct Known Subclasses:
Bindables.BindableSort,CassandraSort,ElasticsearchSort,EnumerableLimitSort,EnumerableSort,GeodeSort,InnodbSort,JdbcRules.JdbcSort,LogicalSort,MongoSort
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.calcite.rel.RelNode
RelNode.Context -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal RelCollationfinal @Nullable RexNodeprotected final com.google.common.collect.ImmutableList<RelHint>final @Nullable RexNodeFields inherited from class org.apache.calcite.rel.AbstractRelNode
digest, id, rowType, traitSet -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSort(RelOptCluster cluster, RelTraitSet traits, List<RelHint> hints, RelNode child, RelCollation collation, @Nullable RexNode offset, @Nullable RexNode fetch) Creates a Sort.protectedSort(RelOptCluster cluster, RelTraitSet traits, RelNode child, RelCollation collation) Creates a Sort.protectedSort(RelOptCluster cluster, RelTraitSet traits, RelNode child, RelCollation collation, @Nullable RexNode offset, @Nullable RexNode fetch) Creates a Sort.protectedCreates a Sort by parsing serialized output. -
Method Summary
Modifier and TypeMethodDescriptionaccept(RexShuttle shuttle) Accepts a visit from a shuttle.@Nullable RelOptCostcomputeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) Returns the cost of this plan (not including children).final Sortcopy(RelTraitSet traitSet, List<RelNode> inputs) Creates a copy of this relational expression, perhaps changing traits and inputs.final Sortcopy(RelTraitSet traitSet, RelNode newInput, RelCollation newCollation) abstract Sortcopy(RelTraitSet traitSet, RelNode newInput, RelCollation newCollation, @Nullable RexNode offset, @Nullable RexNode fetch) Describes the inputs and attributes of this relational expression.Returns the array ofRelFieldCollations asked for by the sort specification, from most significant to least significant.com.google.common.collect.ImmutableList<RelHint>getHints()Returns the hints of this relational expressions as an immutable list.Returns the sort expressions.booleanIndicates whether it is an enforcer operator, e.g.Methods inherited from class org.apache.calcite.rel.SingleRel
childrenAccept, deriveRowType, estimateRowCount, getInput, getInputs, replaceInputMethods inherited from class org.apache.calcite.rel.AbstractRelNode
accept, collectVariablesSet, collectVariablesUsed, deepEquals, deepHashCode, equals, explain, getCluster, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getRelDigest, getRelTypeName, getRowType, getTable, getTraitSet, getVariablesSet, hashCode, isValid, metadata, onRegister, recomputeDigest, register, sole, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.calcite.rel.hint.Hintable
attachHints, withHintsMethods inherited from interface org.apache.calcite.rel.RelNode
explain, fieldIsNullable, stripped
-
Field Details
-
collation
-
offset
-
fetch
-
hints
-
-
Constructor Details
-
Sort
protected Sort(RelOptCluster cluster, RelTraitSet traits, List<RelHint> hints, RelNode child, RelCollation collation, @Nullable RexNode offset, @Nullable RexNode fetch) Creates a Sort.- Parameters:
cluster- Cluster this relational expression belongs totraits- Traitshints- Hints for this nodechild- input relational expressioncollation- array of sort specificationsoffset- Expression for number of rows to discard before returning first rowfetch- Expression for number of rows to fetch
-
Sort
Creates a Sort.- Parameters:
cluster- Cluster this relational expression belongs totraits- Traitschild- input relational expressioncollation- array of sort specifications
-
Sort
protected Sort(RelOptCluster cluster, RelTraitSet traits, RelNode child, RelCollation collation, @Nullable RexNode offset, @Nullable RexNode fetch) Creates a Sort.- Parameters:
cluster- Cluster this relational expression belongs totraits- Traitschild- input relational expressioncollation- array of sort specificationsoffset- Expression for number of rows to discard before returning first rowfetch- Expression for number of rows to fetch
-
Sort
Creates a Sort by parsing serialized output.
-
-
Method Details
-
copy
Description copied from interface:RelNodeCreates 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:
copyin interfaceRelNode- Overrides:
copyin classAbstractRelNode- Parameters:
traitSet- Trait setinputs- Inputs- Returns:
- Copy of this relational expression, substituting traits and inputs
-
copy
-
copy
public abstract Sort copy(RelTraitSet traitSet, RelNode newInput, RelCollation newCollation, @Nullable RexNode offset, @Nullable RexNode fetch) -
computeSelfCost
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.The CPU cost of a Sort has three main cases:
- If
fetchis zero, CPU cost is zero; otherwise, - if the sort keys are empty, we don't need to sort, only step over
the rows, and therefore the CPU cost is
min(fetch + offset, inputRowCount) * bytesPerRow; otherwise - we need to read and sort
inputRowCountrows, with at mostmin(fetch + offset, inputRowCount)of them in the sort data structure at a time, giving a CPU cost ofinputRowCount * log(min(fetch + offset, inputRowCount)) * bytesPerRow.
The cost model factors in row width via
bytesPerRow, because sorts need to move rows around, not just compare them; by making the cost higher if rows are wider, we discourage pushing a Project through a Sort. We assume that each field is 4 bytes, and we add 3 'virtual fields' to represent the per-row overhead. Thus a 1-field row is (3 + 1) * 4 = 16 bytes; a 5-field row is (3 + 5) * 4 = 32 bytes.The cost model does not consider a 5-field sort to be more expensive than, say, a 2-field sort, because both sorts will compare just one field most of the time.
- Specified by:
computeSelfCostin interfaceRelNode- Overrides:
computeSelfCostin classAbstractRelNode- Parameters:
planner- Planner for cost calculationmq- Metadata query- Returns:
- Cost of this plan (not including children)
- If
-
accept
Description copied from interface:RelNodeAccepts a visit from a shuttle. If the shuttle updates expression, then a copy of the relation should be created. This new relation might have a different row-type.- Specified by:
acceptin interfaceRelNode- Overrides:
acceptin classAbstractRelNode- Parameters:
shuttle- Shuttle- Returns:
- A copy of this node incorporating changes made by the shuttle to this node's children
-
isEnforcer
public boolean isEnforcer()Description copied from interface:RelNodeIndicates whether it is an enforcer operator, e.g. PhysicalSort, PhysicalHashDistribute, etc. As an enforcer, the operator must be created only when required traitSet is not satisfied by its input.- Specified by:
isEnforcerin interfaceRelNode- Overrides:
isEnforcerin classAbstractRelNode- Returns:
- Whether it is an enforcer operator
-
getCollation
Returns the array ofRelFieldCollations asked for by the sort specification, from most significant to least significant.See also
RelMetadataQuery.collations(RelNode), which lists all known collations. For example,ORDER BY time_idmight also be sorted bythe_year, the_monthbecause of a known monotonicity constraint among the columns.getCollationwould return[time_id]andcollationswould return[ [time_id], [the_year, the_month] ]. -
getSortExps
Returns the sort expressions. -
explainTerms
Description copied from class:AbstractRelNodeDescribes the inputs and attributes of this relational expression. Each node should callsuper.explainTerms, then call theRelWriter.input(String, RelNode)andRelWriter.item(String, Object)methods for each input and attribute.- Overrides:
explainTermsin classSingleRel- Parameters:
pw- Plan writer- Returns:
- Plan writer for fluent-explain pattern
-
getHints
Description copied from interface:HintableReturns the hints of this relational expressions as an immutable list.
-