Class RelMetadataQuery
RelMetadataProvider for the set of relational expression metadata
 queries defined as standard within Calcite. The Javadoc on these methods
 serves as their primary specification.
 To add a new standard query Xyz to this interface, follow
 these steps:
 
- Add a static method getXyzspecification to this class.
- Add unit tests to org.apache.calcite.test.RelMetadataTest.
- Write a new provider class RelMdXyzin this package. Follow the pattern from an existing class such asRelMdColumnOrigins, overloading on all of the logical relational expressions to which the query applies.
- Add a SOURCEstatic member, similar toRelMdColumnOrigins.SOURCE.
- Register the SOURCEobject inDefaultRelMetadataProvider.
- Get unit tests working.
Because relational expression metadata is extensible, extension projects
 can define similar facades in order to specify access to custom metadata.
 Please do not add queries here (nor on RelNode) which lack meaning
 outside of your extension.
 
Besides adding new metadata queries, extension projects may need to add
 custom providers for the standard queries in order to handle additional
 relational expressions (either logical or physical). In either case, the
 process is the same: write a reflective provider and chain it on to an
 instance of DefaultRelMetadataProvider, pre-pending it to the default
 providers. Then supply that instance to the planner via the appropriate
 plugin mechanism.
- 
Field SummaryFields inherited from class org.apache.calcite.rel.metadata.RelMetadataQueryBasemap, metadataProvider, THREAD_PROVIDERS
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCreates the instance withJaninoRelMetadataProviderinstance fromRelMetadataQueryBase.THREAD_PROVIDERSandEMPTYas a prototype.RelMetadataQuery(MetadataHandlerProvider provider) Create a RelMetadataQuery with a givenMetadataHandlerProvider.
- 
Method SummaryModifier and TypeMethodDescription@Nullable BooleanareColumnsUnique(RelNode rel, ImmutableBitSet columns) Returns theBuiltInMetadata.ColumnUniqueness.areColumnsUnique(ImmutableBitSet, boolean)statistic.@Nullable BooleanareColumnsUnique(RelNode rel, ImmutableBitSet columns, boolean ignoreNulls) Returns theBuiltInMetadata.ColumnUniqueness.areColumnsUnique(ImmutableBitSet, boolean)statistic.@Nullable BooleanareRowsUnique(RelNode rel) Returns whether the rows of a given relational expression are distinct.@Nullable BooleanareRowsUnique(RelNode rel, boolean ignoreNulls) Returns whether the rows of a given relational expression are distinct, optionally ignoring NULL values.@Nullable com.google.common.collect.ImmutableList<RelCollation>collations(RelNode rel) Returns theBuiltInMetadata.Collation.collations()statistic.@Nullable DoubleReturns theBuiltInMetadata.Memory.cumulativeMemoryWithinPhase()statistic.@Nullable DoubleReturns theBuiltInMetadata.Memory.cumulativeMemoryWithinPhaseSplit()statistic.distribution(RelNode rel) Returns theBuiltInMetadata.Distribution.distribution()statistic.expand(RelNode rel, int column, BuiltInMetadata.Measure.Context context) Returns theBuiltInMetadata.Measure.expand(int, BuiltInMetadata.Measure.Context)statistic.@Nullable RelOptPredicateListgetAllPredicates(RelNode rel) Returns theBuiltInMetadata.AllPredicates.getAllPredicates()statistic.Returns theBuiltInMetadata.Size.averageColumnSizes()statistic.AsgetAverageColumnSizes(org.apache.calcite.rel.RelNode)but never returns a null list, only ever a list of nulls.@Nullable DoublegetAverageRowSize(RelNode rel) Returns theBuiltInMetadata.Size.averageRowSize()statistic.@Nullable RelColumnOrigingetColumnOrigin(RelNode rel, int column) Determines the origin of a column.@Nullable Set<RelColumnOrigin>getColumnOrigins(RelNode rel, int column) Returns theBuiltInMetadata.ColumnOrigin.getColumnOrigins(int)statistic.@Nullable RelOptCostgetCumulativeCost(RelNode rel) Returns theBuiltInMetadata.CumulativeCost.getCumulativeCost()statistic.@Nullable DoublegetDistinctRowCount(RelNode rel, ImmutableBitSet groupKey, @Nullable RexNode predicate) Returns theBuiltInMetadata.DistinctRowCount.getDistinctRowCount(ImmutableBitSet, RexNode)statistic.@Nullable RelDistributiongetDistribution(RelNode rel) Returns theBuiltInMetadata.Distribution.distribution()statistic.getExpressionLineage(RelNode rel, RexNode expression) Determines the origin of a column.@Nullable RelOptCostgetLowerBoundCost(RelNode rel, VolcanoPlanner planner) Returns the lower bound cost of a RelNode.@Nullable DoublegetMaxRowCount(RelNode rel) Returns theBuiltInMetadata.MaxRowCount.getMaxRowCount()statistic.@Nullable DoublegetMinRowCount(RelNode rel) Returns theBuiltInMetadata.MinRowCount.getMinRowCount()statistic.getNodeTypes(RelNode rel) Returns theBuiltInMetadata.NodeTypes.getNodeTypes()statistic.@Nullable RelOptCostReturns theBuiltInMetadata.NonCumulativeCost.getNonCumulativeCost()statistic.@Nullable DoubleReturns theBuiltInMetadata.PercentageOriginalRows.getPercentageOriginalRows()statistic.@Nullable DoublegetPopulationSize(RelNode rel, ImmutableBitSet groupKey) Returns theBuiltInMetadata.PopulationSize.getPopulationSize(ImmutableBitSet)statistic.Returns theBuiltInMetadata.Predicates.getPredicates()statistic.getRowCount(RelNode rel) Returns theBuiltInMetadata.RowCount.getRowCount()statistic.@Nullable DoublegetSelectivity(RelNode rel, @Nullable RexNode predicate) Returns theBuiltInMetadata.Selectivity.getSelectivity(RexNode)statistic.@Nullable RelOptTablegetTableOrigin(RelNode rel) Determines the origin of aRelNode, provided it maps to a single table, optionally with filtering and projection.@Nullable Set<RexTableInputRef.RelTableRef>Determines the tables used by a plan.@Nullable Set<ImmutableBitSet>getUniqueKeys(RelNode rel) Returns theBuiltInMetadata.UniqueKeys.getUniqueKeys(boolean)statistic.@Nullable Set<ImmutableBitSet>getUniqueKeys(RelNode rel, boolean ignoreNulls) Returns theBuiltInMetadata.UniqueKeys.getUniqueKeys(boolean)statistic.static RelMetadataQueryinstance()Returns an instance of RelMetadataQuery.@Nullable BooleanReturns whether the return rows of a given relational expression are empty.@Nullable BooleanReturns theBuiltInMetadata.Measure.isMeasure(int)statistic.@Nullable BooleanisPhaseTransition(RelNode rel) Returns theBuiltInMetadata.Parallelism.isPhaseTransition()statistic.isVisibleInExplain(RelNode rel, SqlExplainLevel explainLevel) Returns theBuiltInMetadata.ExplainVisibility.isVisibleInExplain(SqlExplainLevel)statistic.@Nullable DoubleReturns theBuiltInMetadata.Memory.memory()statistic.@Nullable IntegersplitCount(RelNode rel) Returns theBuiltInMetadata.Parallelism.splitCount()statistic.Methods inherited from class org.apache.calcite.rel.metadata.RelMetadataQueryBaseclearCache, handler, initialHandler, revise, revise
- 
Constructor Details- 
RelMetadataQueryprotected RelMetadataQuery()Creates the instance withJaninoRelMetadataProviderinstance fromRelMetadataQueryBase.THREAD_PROVIDERSandEMPTYas a prototype.
- 
RelMetadataQueryCreate a RelMetadataQuery with a givenMetadataHandlerProvider.- Parameters:
- provider- The provider to use for construction.
 
 
- 
- 
Method Details- 
instanceReturns an instance of RelMetadataQuery. It ensures that cycles do not occur while computing metadata.
- 
getNodeTypespublic @Nullable com.google.common.collect.Multimap<Class<? extends RelNode>,RelNode> getNodeTypes(RelNode rel) Returns theBuiltInMetadata.NodeTypes.getNodeTypes()statistic.- Parameters:
- rel- the relational expression
 
- 
getRowCountReturns theBuiltInMetadata.RowCount.getRowCount()statistic.- Parameters:
- rel- the relational expression
- Returns:
- estimated row count, or null if no reliable estimate can be determined
 
- 
getMaxRowCountReturns theBuiltInMetadata.MaxRowCount.getMaxRowCount()statistic.- Parameters:
- rel- the relational expression
- Returns:
- max row count
 
- 
getMinRowCountReturns theBuiltInMetadata.MinRowCount.getMinRowCount()statistic.- Parameters:
- rel- the relational expression
- Returns:
- min row count
 
- 
isEmptyReturns whether the return rows of a given relational expression are empty.- Parameters:
- relNode- the relational expression
- Returns:
- true or false depending on whether the return rows are empty, or null if not enough information is available to make that determination
 
- 
getCumulativeCostReturns theBuiltInMetadata.CumulativeCost.getCumulativeCost()statistic.- Parameters:
- rel- the relational expression
- Returns:
- estimated cost, or null if no reliable estimate can be determined
 
- 
getNonCumulativeCostReturns theBuiltInMetadata.NonCumulativeCost.getNonCumulativeCost()statistic.- Parameters:
- rel- the relational expression
- Returns:
- estimated cost, or null if no reliable estimate can be determined
 
- 
getPercentageOriginalRowsReturns theBuiltInMetadata.PercentageOriginalRows.getPercentageOriginalRows()statistic.- Parameters:
- rel- the relational expression
- Returns:
- estimated percentage (between 0.0 and 1.0), or null if no reliable estimate can be determined
 
- 
getColumnOriginsReturns theBuiltInMetadata.ColumnOrigin.getColumnOrigins(int)statistic.- Parameters:
- rel- the relational expression
- column- 0-based ordinal for output column of interest
- Returns:
- set of origin columns, or null if this information cannot be determined (whereas empty set indicates definitely no origin columns at all)
 
- 
getColumnOriginDetermines the origin of a column.- Parameters:
- rel- the RelNode of the column
- column- the offset of the column whose origin we are trying to determine
- Returns:
- the origin of a column
- See Also:
 
- 
getExpressionLineageDetermines the origin of a column.
- 
getTableReferencesDetermines the tables used by a plan.
- 
getTableOriginDetermines the origin of aRelNode, provided it maps to a single table, optionally with filtering and projection.- Parameters:
- rel- the RelNode
- Returns:
- the table, if the RelNode is a simple table; otherwise null
 
- 
getSelectivityReturns theBuiltInMetadata.Selectivity.getSelectivity(RexNode)statistic.- Parameters:
- rel- the relational expression
- predicate- predicate whose selectivity is to be estimated against- rel's output
- Returns:
- estimated selectivity (between 0.0 and 1.0), or null if no reliable estimate can be determined
 
- 
getUniqueKeysReturns theBuiltInMetadata.UniqueKeys.getUniqueKeys(boolean)statistic.- Parameters:
- rel- the relational expression
- Returns:
- set of keys, or null if this information cannot be determined (whereas empty set indicates definitely no keys at all)
 
- 
getUniqueKeysReturns theBuiltInMetadata.UniqueKeys.getUniqueKeys(boolean)statistic.- Parameters:
- rel- the relational expression
- ignoreNulls- if true, ignore null values when determining whether the keys are unique
- Returns:
- set of keys, or null if this information cannot be determined (whereas empty set indicates definitely no keys at all)
 
- 
areRowsUniqueReturns whether the rows of a given relational expression are distinct, optionally ignoring NULL values.This is derived by applying the BuiltInMetadata.ColumnUniqueness.areColumnsUnique(org.apache.calcite.util.ImmutableBitSet, boolean)statistic over all columns. IfBuiltInMetadata.MaxRowCount.getMaxRowCount()is less than or equal to one, we shortcut the process and declare the rows unique.- Parameters:
- rel- the relational expression
- ignoreNulls- if true, ignore null values when determining column uniqueness
- Returns:
- whether the rows are unique, or null if not enough information is available to make that determination
 
- 
areRowsUniqueReturns whether the rows of a given relational expression are distinct.Derived by calling areRowsUnique(RelNode, boolean).- Parameters:
- rel- the relational expression
- Returns:
- whether the rows are unique, or null if not enough information is available to make that determination
 
- 
areColumnsUniqueReturns theBuiltInMetadata.ColumnUniqueness.areColumnsUnique(ImmutableBitSet, boolean)statistic.- Parameters:
- rel- the relational expression
- columns- column mask representing the subset of columns for which uniqueness will be determined
- Returns:
- true or false depending on whether the columns are unique, or null if not enough information is available to make that determination
 
- 
areColumnsUniquepublic @Nullable Boolean areColumnsUnique(RelNode rel, ImmutableBitSet columns, boolean ignoreNulls) Returns theBuiltInMetadata.ColumnUniqueness.areColumnsUnique(ImmutableBitSet, boolean)statistic.- Parameters:
- rel- the relational expression
- columns- column mask representing the subset of columns for which uniqueness will be determined
- ignoreNulls- if true, ignore null values when determining column uniqueness
- Returns:
- true or false depending on whether the columns are unique, or null if not enough information is available to make that determination
 
- 
collationsReturns theBuiltInMetadata.Collation.collations()statistic.- Parameters:
- rel- the relational expression
- Returns:
- List of sorted column combinations, or null if not enough information is available to make that determination
 
- 
distributionReturns theBuiltInMetadata.Distribution.distribution()statistic.- Parameters:
- rel- the relational expression
- Returns:
- List of sorted column combinations, or null if not enough information is available to make that determination
 
- 
getPopulationSizeReturns theBuiltInMetadata.PopulationSize.getPopulationSize(ImmutableBitSet)statistic.- Parameters:
- rel- the relational expression
- groupKey- column mask representing the subset of columns for which the row count will be determined
- Returns:
- distinct row count for the given groupKey, or null if no reliable estimate can be determined
 
- 
getAverageRowSizeReturns theBuiltInMetadata.Size.averageRowSize()statistic.- Parameters:
- rel- the relational expression
- Returns:
- average size of a row, in bytes, or null if not known
 
- 
getAverageColumnSizesReturns theBuiltInMetadata.Size.averageColumnSizes()statistic.- Parameters:
- rel- the relational expression
- Returns:
- a list containing, for each column, the average size of a column value, in bytes. Each value or the entire list may be null if the metadata is not available
 
- 
getAverageColumnSizesNotNullAsgetAverageColumnSizes(org.apache.calcite.rel.RelNode)but never returns a null list, only ever a list of nulls.
- 
isPhaseTransitionReturns theBuiltInMetadata.Parallelism.isPhaseTransition()statistic.- Parameters:
- rel- the relational expression
- Returns:
- whether each physical operator implementing this relational expression belongs to a different process than its inputs, or null if not known
 
- 
splitCountReturns theBuiltInMetadata.Parallelism.splitCount()statistic.- Parameters:
- rel- the relational expression
- Returns:
- the number of distinct splits of the data, or null if not known
 
- 
memoryReturns theBuiltInMetadata.Memory.memory()statistic.- Parameters:
- rel- the relational expression
- Returns:
- the expected amount of memory, in bytes, required by a physical operator implementing this relational expression, across all splits, or null if not known
 
- 
cumulativeMemoryWithinPhaseReturns theBuiltInMetadata.Memory.cumulativeMemoryWithinPhase()statistic.- Parameters:
- rel- the relational expression
- Returns:
- the cumulative amount of memory, in bytes, required by the physical operator implementing this relational expression, and all other operators within the same phase, across all splits, or null if not known
 
- 
cumulativeMemoryWithinPhaseSplitReturns theBuiltInMetadata.Memory.cumulativeMemoryWithinPhaseSplit()statistic.- Parameters:
- rel- the relational expression
- Returns:
- the expected cumulative amount of memory, in bytes, required by the physical operator implementing this relational expression, and all operators within the same phase, within each split, or null if not known
 
- 
isMeasureReturns theBuiltInMetadata.Measure.isMeasure(int)statistic.- Parameters:
- rel- The relational expression
- column- Output column of the relational expression
- Returns:
- whether column is a measure
 
- 
expandReturns theBuiltInMetadata.Measure.expand(int, BuiltInMetadata.Measure.Context)statistic.- Parameters:
- rel- The relational expression
- column- Output column of the relational expression
- context- Context of the use of the measure
- Returns:
- expression for measure in the context
 
- 
getDistinctRowCountpublic @Nullable Double getDistinctRowCount(RelNode rel, ImmutableBitSet groupKey, @Nullable RexNode predicate) Returns theBuiltInMetadata.DistinctRowCount.getDistinctRowCount(ImmutableBitSet, RexNode)statistic.- Parameters:
- rel- the relational expression
- groupKey- column mask representing group by columns
- predicate- pre-filtered predicates
- Returns:
- distinct row count for groupKey, filtered by predicate, or null if no reliable estimate can be determined
 
- 
getPulledUpPredicatesReturns theBuiltInMetadata.Predicates.getPredicates()statistic.- Parameters:
- rel- the relational expression
- Returns:
- Predicates that can be pulled above this RelNode
 
- 
getAllPredicatesReturns theBuiltInMetadata.AllPredicates.getAllPredicates()statistic.- Parameters:
- rel- the relational expression
- Returns:
- All predicates within and below this RelNode
 
- 
isVisibleInExplainReturns theBuiltInMetadata.ExplainVisibility.isVisibleInExplain(SqlExplainLevel)statistic.- Parameters:
- rel- the relational expression
- explainLevel- level of detail
- Returns:
- true for visible, false for invisible; if no metadata is available, defaults to true
 
- 
getDistributionReturns theBuiltInMetadata.Distribution.distribution()statistic.- Parameters:
- rel- the relational expression
- Returns:
- description of how the rows in the relational expression are physically distributed
 
- 
getLowerBoundCostReturns the lower bound cost of a RelNode.
 
-