Class RelMdCollation
- java.lang.Object
-
- org.apache.calcite.rel.metadata.RelMdCollation
-
- All Implemented Interfaces:
MetadataHandler<BuiltInMetadata.Collation>
public class RelMdCollation extends java.lang.Object implements MetadataHandler<BuiltInMetadata.Collation>
RelMdCollation supplies a default implementation ofRelMetadataQuery.collations(org.apache.calcite.rel.RelNode)
for the standard logical algebra.
-
-
Field Summary
Fields Modifier and Type Field Description static RelMetadataProvider
SOURCE
-
Constructor Summary
Constructors Modifier Constructor Description private
RelMdCollation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.List<RelCollation>
calc(RelMetadataQuery mq, RelNode input, RexProgram program)
Helper method to determine aCalc
's collation.com.google.common.collect.ImmutableList<RelCollation>
collations(EnumerableMergeJoin join, 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(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(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.private static com.google.common.collect.Ordering<java.util.List<RexLiteral>>
comparator(RelFieldCollation fieldCollation)
static java.util.List<RelCollation>
filter(RelMetadataQuery mq, RelNode input)
Helper method to determine aFilter
's collation.MetadataDef<BuiltInMetadata.Collation>
getDef()
static java.util.List<RelCollation>
limit(RelMetadataQuery mq, RelNode input)
Helper method to determine a limit's collation.static java.util.List<RelCollation>
mergeJoin(RelMetadataQuery mq, RelNode left, RelNode right, ImmutableIntList leftKeys, ImmutableIntList rightKeys)
Helper method to determine aJoin
's collation assuming that it uses a merge-join algorithm.static java.util.List<RelCollation>
project(RelMetadataQuery mq, RelNode input, java.util.List<? extends RexNode> projects)
Helper method to determine aProject
's collation.static java.util.List<RelCollation>
sort(RelCollation collation)
Helper method to determine aSort
's collation.static java.util.List<RelCollation>
table(RelOptTable table)
Helper method to determine aTableScan
's collation.static java.util.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 java.util.List<RelCollation>
window(RelMetadataQuery mq, RelNode input, com.google.common.collect.ImmutableList<Window.Group> groups)
Helper method to determine aWindow
's collation.
-
-
-
Field Detail
-
SOURCE
public static final RelMetadataProvider SOURCE
-
-
Method Detail
-
getDef
public MetadataDef<BuiltInMetadata.Collation> 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
,SemiJoin
,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(Filter 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(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(HepRelVertex rel, RelMetadataQuery mq)
-
collations
public com.google.common.collect.ImmutableList<RelCollation> collations(RelSubset rel, RelMetadataQuery mq)
-
table
public static java.util.List<RelCollation> table(RelOptTable table)
Helper method to determine aTableScan
's collation.
-
sort
public static java.util.List<RelCollation> sort(RelCollation collation)
Helper method to determine aSort
's collation.
-
filter
public static java.util.List<RelCollation> filter(RelMetadataQuery mq, RelNode input)
Helper method to determine aFilter
's collation.
-
limit
public static java.util.List<RelCollation> limit(RelMetadataQuery mq, RelNode input)
Helper method to determine a limit's collation.
-
calc
public static java.util.List<RelCollation> calc(RelMetadataQuery mq, RelNode input, RexProgram program)
Helper method to determine aCalc
's collation.
-
project
public static java.util.List<RelCollation> project(RelMetadataQuery mq, RelNode input, java.util.List<? extends RexNode> projects)
Helper method to determine aProject
's collation.
-
window
public static java.util.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.
-
values
public static java.util.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
private static com.google.common.collect.Ordering<java.util.List<RexLiteral>> comparator(RelFieldCollation fieldCollation)
-
mergeJoin
public static java.util.List<RelCollation> mergeJoin(RelMetadataQuery mq, RelNode left, RelNode right, ImmutableIntList leftKeys, ImmutableIntList rightKeys)
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.
-
-