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
Modifier and TypeFieldDescriptionfinal RelCollation
final @Nullable RexNode
protected final com.google.common.collect.ImmutableList<RelHint>
final @Nullable RexNode
Fields inherited from class org.apache.calcite.rel.AbstractRelNode
digest, id, rowType, traitSet
-
Constructor Summary
ModifierConstructorDescriptionprotected
Sort
(RelOptCluster cluster, RelTraitSet traits, List<RelHint> hints, RelNode child, RelCollation collation, @Nullable RexNode offset, @Nullable RexNode fetch) Creates a Sort.protected
Sort
(RelOptCluster cluster, RelTraitSet traits, RelNode child, RelCollation collation) Creates a Sort.protected
Sort
(RelOptCluster cluster, RelTraitSet traits, RelNode child, RelCollation collation, @Nullable RexNode offset, @Nullable RexNode fetch) Creates a Sort.protected
Creates a Sort by parsing serialized output. -
Method Summary
Modifier and TypeMethodDescriptionaccept
(RexShuttle shuttle) Accepts a visit from a shuttle.@Nullable RelOptCost
computeSelfCost
(RelOptPlanner planner, RelMetadataQuery mq) Returns the cost of this plan (not including children).final Sort
copy
(RelTraitSet traitSet, List<RelNode> inputs) Creates a copy of this relational expression, perhaps changing traits and inputs.final Sort
copy
(RelTraitSet traitSet, RelNode newInput, RelCollation newCollation) abstract Sort
copy
(RelTraitSet traitSet, RelNode newInput, RelCollation newCollation, @Nullable RexNode offset, @Nullable RexNode fetch) Describes the inputs and attributes of this relational expression.Returns the array ofRelFieldCollation
s 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.boolean
Indicates whether it is an enforcer operator, e.g.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, 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, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.calcite.rel.hint.Hintable
attachHints, withHints
Methods 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: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 interfaceRelNode
- Overrides:
copy
in 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
fetch
is 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
inputRowCount
rows, 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:
computeSelfCost
in interfaceRelNode
- Overrides:
computeSelfCost
in classAbstractRelNode
- Parameters:
planner
- Planner for cost calculationmq
- Metadata query- Returns:
- Cost of this plan (not including children)
- If
-
accept
Description copied from interface:RelNode
Accepts 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:
accept
in interfaceRelNode
- Overrides:
accept
in 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:RelNode
Indicates 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:
isEnforcer
in interfaceRelNode
- Overrides:
isEnforcer
in classAbstractRelNode
- Returns:
- Whether it is an enforcer operator
-
getCollation
Returns the array ofRelFieldCollation
s 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_id
might also be sorted bythe_year, the_month
because of a known monotonicity constraint among the columns.getCollation
would return[time_id]
andcollations
would return[ [time_id], [the_year, the_month] ]
. -
getSortExps
Returns the sort expressions. -
explainTerms
Description copied from class:AbstractRelNode
Describes 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:
explainTerms
in classSingleRel
- Parameters:
pw
- Plan writer- Returns:
- Plan writer for fluent-explain pattern
-
getHints
Description copied from interface:Hintable
Returns the hints of this relational expressions as an immutable list.
-