Class RelMdCollation
- All Implemented Interfaces:
MetadataHandler<BuiltInMetadata.Collation>
public class RelMdCollation extends Object implements MetadataHandler<BuiltInMetadata.Collation>
RelMetadataQuery.collations(org.apache.calcite.rel.RelNode)
for the standard logical algebra.-
Field Summary
Fields Modifier and Type Field Description static RelMetadataProvider
SOURCE
-
Method Summary
Modifier and Type Method Description static List<RelCollation>
calc(RelMetadataQuery mq, RelNode input, RexProgram program)
Helper method to determine aCalc
's collation.com.google.common.collect.ImmutableList<RelCollation>
collations(EnumerableCorrelate join, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(EnumerableHashJoin join, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(EnumerableMergeJoin join, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(EnumerableNestedLoopJoin join, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(JdbcToEnumerableConverter rel, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(HepRelVertex rel, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(RelSubset rel, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(Calc calc, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(Filter rel, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(Match rel, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(Project project, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(SortExchange sort, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(Sort sort, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(TableModify rel, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(TableScan scan, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(Values values, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(Window rel, RelMetadataQuery mq)
com.google.common.collect.ImmutableList<RelCollation>
collations(RelNode rel, RelMetadataQuery mq)
Catch-all implementation forBuiltInMetadata.Collation.collations()
, invoked using reflection, for any relational expression not handled by a more specific method.static com.google.common.collect.Ordering<List<RexLiteral>>
comparator(RelFieldCollation fieldCollation)
static List<RelCollation>
enumerableBatchNestedLoopJoin(RelMetadataQuery mq, RelNode left, RelNode right, JoinRelType joinType)
static List<RelCollation>
enumerableCorrelate(RelMetadataQuery mq, RelNode left, RelNode right, JoinRelType joinType)
static List<RelCollation>
enumerableHashJoin(RelMetadataQuery mq, RelNode left, RelNode right, JoinRelType joinType)
Returns the collation ofEnumerableHashJoin
based on its inputs and the join type.static List<RelCollation>
enumerableNestedLoopJoin(RelMetadataQuery mq, RelNode left, RelNode right, JoinRelType joinType)
Returns the collation ofEnumerableNestedLoopJoin
based on its inputs and the join type.static List<RelCollation>
enumerableSemiJoin(RelMetadataQuery mq, RelNode left, RelNode right)
static List<RelCollation>
filter(RelMetadataQuery mq, RelNode input)
Helper method to determine aFilter
's collation.MetadataDef<BuiltInMetadata.Collation>
getDef()
static List<RelCollation>
limit(RelMetadataQuery mq, RelNode input)
Helper method to determine a limit's collation.static List<RelCollation>
match(RelMetadataQuery mq, RelNode input, RelDataType rowType, RexNode pattern, boolean strictStart, boolean strictEnd, Map<String,RexNode> patternDefinitions, Map<String,RexNode> measures, RexNode after, Map<String,? extends SortedSet<String>> subsets, boolean allRows, ImmutableBitSet partitionKeys, RelCollation orderKeys, RexNode interval)
Helper method to determine aMatch
's collation.static List<RelCollation>
mergeJoin(RelMetadataQuery mq, RelNode left, RelNode right, ImmutableIntList leftKeys, ImmutableIntList rightKeys)
static List<RelCollation>
mergeJoin(RelMetadataQuery mq, RelNode left, RelNode right, ImmutableIntList leftKeys, ImmutableIntList rightKeys, JoinRelType joinType)
Helper method to determine aJoin
's collation assuming that it uses a merge-join algorithm.static List<RelCollation>
project(RelMetadataQuery mq, RelNode input, List<? extends RexNode> projects)
Helper method to determine aProject
's collation.static List<RelCollation>
snapshot(RelMetadataQuery mq, RelNode input)
Helper method to determine aSnapshot
's collation.static List<RelCollation>
sort(RelCollation collation)
Helper method to determine aSort
's collation.static List<RelCollation>
table(RelOptTable table)
Helper method to determine aTableScan
's collation.static List<RelCollation>
values(RelMetadataQuery mq, RelDataType rowType, com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<RexLiteral>> tuples)
Helper method to determine aValues
's collation.static List<RelCollation>
window(RelMetadataQuery mq, RelNode input, com.google.common.collect.ImmutableList<Window.Group> groups)
Helper method to determine aWindow
's collation.
-
Field Details
-
Method Details
-
getDef
- Specified by:
getDef
in interfaceMetadataHandler<BuiltInMetadata.Collation>
-
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(RelNode rel, RelMetadataQuery mq)Catch-all implementation forBuiltInMetadata.Collation.collations()
, invoked using reflection, for any relational expression not handled by a more specific method.Union
,Intersect
,Minus
,Join
,Correlate
do not in general return sorted results (but implementations using particular algorithms may).- Parameters:
rel
- Relational expression- Returns:
- Relational expression's collations
- See Also:
RelMetadataQuery.collations(RelNode)
-
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(Window rel, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(Match rel, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(Filter rel, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(TableModify rel, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(TableScan scan, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(EnumerableMergeJoin join, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(EnumerableHashJoin join, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(EnumerableNestedLoopJoin join, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(EnumerableCorrelate join, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(Sort sort, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(SortExchange sort, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(Project project, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(Calc calc, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(Values values, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(JdbcToEnumerableConverter rel, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(HepRelVertex rel, RelMetadataQuery mq) -
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(RelSubset rel, RelMetadataQuery mq) -
table
Helper method to determine aTableScan
's collation. -
snapshot
Helper method to determine aSnapshot
's collation. -
sort
Helper method to determine aSort
's collation. -
filter
Helper method to determine aFilter
's collation. -
limit
Helper method to determine a limit's collation. -
calc
Helper method to determine aCalc
's collation. -
project
public static List<RelCollation> project(RelMetadataQuery mq, RelNode input, List<? extends RexNode> projects)Helper method to determine aProject
's collation. -
window
public static List<RelCollation> window(RelMetadataQuery mq, RelNode input, com.google.common.collect.ImmutableList<Window.Group> groups)Helper method to determine aWindow
's collation.A Window projects the fields of its input first, followed by the output from each of its windows. Assuming (quite reasonably) that the implementation does not re-order its input rows, then any collations of its input are preserved.
-
match
public static List<RelCollation> match(RelMetadataQuery mq, RelNode input, RelDataType rowType, RexNode pattern, boolean strictStart, boolean strictEnd, Map<String,RexNode> patternDefinitions, Map<String,RexNode> measures, RexNode after, Map<String,? extends SortedSet<String>> subsets, boolean allRows, ImmutableBitSet partitionKeys, RelCollation orderKeys, RexNode interval)Helper method to determine aMatch
's collation. -
values
public static List<RelCollation> values(RelMetadataQuery mq, RelDataType rowType, com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<RexLiteral>> tuples)Helper method to determine aValues
's collation.We actually under-report the collations. A Values with 0 or 1 rows - an edge case, but legitimate and very common - is ordered by every permutation of every subset of the columns.
So, our algorithm aims to:
- produce at most N collations (where N is the number of columns);
- make each collation as long as possible;
- do not repeat combinations already emitted -
if we've emitted
(a, b)
do not later emit(b, a)
; - probe the actual values and make sure that each collation is consistent with the data
So, for an empty Values with 4 columns, we would emit
(a, b, c, d), (b, c, d), (c, d), (d)
. -
comparator
public static com.google.common.collect.Ordering<List<RexLiteral>> comparator(RelFieldCollation fieldCollation) -
mergeJoin
@Deprecated public static List<RelCollation> mergeJoin(RelMetadataQuery mq, RelNode left, RelNode right, ImmutableIntList leftKeys, ImmutableIntList rightKeys)Deprecated.Helper method to determine aJoin
's collation assuming that it uses a merge-join algorithm.If the inputs are sorted on other keys in addition to the join key, the result preserves those collations too.
-
mergeJoin
public static List<RelCollation> mergeJoin(RelMetadataQuery mq, RelNode left, RelNode right, ImmutableIntList leftKeys, ImmutableIntList rightKeys, JoinRelType joinType)Helper method to determine aJoin
's collation assuming that it uses a merge-join algorithm.If the inputs are sorted on other keys in addition to the join key, the result preserves those collations too.
-
enumerableHashJoin
public static List<RelCollation> enumerableHashJoin(RelMetadataQuery mq, RelNode left, RelNode right, JoinRelType joinType)Returns the collation ofEnumerableHashJoin
based on its inputs and the join type. -
enumerableNestedLoopJoin
public static List<RelCollation> enumerableNestedLoopJoin(RelMetadataQuery mq, RelNode left, RelNode right, JoinRelType joinType)Returns the collation ofEnumerableNestedLoopJoin
based on its inputs and the join type. -
enumerableCorrelate
public static List<RelCollation> enumerableCorrelate(RelMetadataQuery mq, RelNode left, RelNode right, JoinRelType joinType) -
enumerableSemiJoin
public static List<RelCollation> enumerableSemiJoin(RelMetadataQuery mq, RelNode left, RelNode right) -
enumerableBatchNestedLoopJoin
public static List<RelCollation> enumerableBatchNestedLoopJoin(RelMetadataQuery mq, RelNode left, RelNode right, JoinRelType joinType)
-