Class RelMetadataQuery
public class RelMetadataQuery extends RelMetadataQueryBase
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
getXyz
specification to this class. - Add unit tests to
org.apache.calcite.test.RelMetadataTest
. - Write a new provider class
RelMdXyz
in 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
SOURCE
static member, similar toRelMdColumnOrigins.SOURCE
. - Register the
SOURCE
object 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 Summary
Fields inherited from class org.apache.calcite.rel.metadata.RelMetadataQueryBase
map, metadataProvider, THREAD_PROVIDERS
-
Constructor Summary
Constructors Modifier Constructor Description protected
RelMetadataQuery()
Creates the instance withJaninoRelMetadataProvider
instance fromRelMetadataQueryBase.THREAD_PROVIDERS
andEMPTY
as a prototype. -
Method Summary
Methods inherited from class org.apache.calcite.rel.metadata.RelMetadataQueryBase
clearCache, initialHandler, revise
-
Constructor Details
-
RelMetadataQuery
protected RelMetadataQuery()Creates the instance withJaninoRelMetadataProvider
instance fromRelMetadataQueryBase.THREAD_PROVIDERS
andEMPTY
as a prototype.
-
-
Method Details
-
instance
Returns an instance of RelMetadataQuery. It ensures that cycles do not occur while computing metadata. -
getNodeTypes
public com.google.common.collect.Multimap<Class<? extends RelNode>,RelNode> getNodeTypes(RelNode rel)Returns theBuiltInMetadata.NodeTypes.getNodeTypes()
statistic.- Parameters:
rel
- the relational expression
-
getRowCount
Returns theBuiltInMetadata.RowCount.getRowCount()
statistic.- Parameters:
rel
- the relational expression- Returns:
- estimated row count, or null if no reliable estimate can be determined
-
getMaxRowCount
Returns theBuiltInMetadata.MaxRowCount.getMaxRowCount()
statistic.- Parameters:
rel
- the relational expression- Returns:
- max row count
-
getMinRowCount
Returns theBuiltInMetadata.MinRowCount.getMinRowCount()
statistic.- Parameters:
rel
- the relational expression- Returns:
- max row count
-
getCumulativeCost
Returns theBuiltInMetadata.CumulativeCost.getCumulativeCost()
statistic.- Parameters:
rel
- the relational expression- Returns:
- estimated cost, or null if no reliable estimate can be determined
-
getNonCumulativeCost
Returns theBuiltInMetadata.NonCumulativeCost.getNonCumulativeCost()
statistic.- Parameters:
rel
- the relational expression- Returns:
- estimated cost, or null if no reliable estimate can be determined
-
getPercentageOriginalRows
Returns 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
-
getColumnOrigins
Returns theBuiltInMetadata.ColumnOrigin.getColumnOrigins(int)
statistic.- Parameters:
rel
- the relational expressioncolumn
- 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)
-
getColumnOrigin
Determines the origin of a column, provided the column maps to a single column that isn't derived.- Parameters:
rel
- the RelNode of the columncolumn
- the offset of the column whose origin we are trying to determine- Returns:
- the origin of a column provided it's a simple column; otherwise, returns null
- See Also:
getColumnOrigins(org.apache.calcite.rel.RelNode, int)
-
getExpressionLineage
Determines the origin of a column. -
getTableReferences
Determines the tables used by a plan. -
getTableOrigin
Determines 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
-
getSelectivity
Returns theBuiltInMetadata.Selectivity.getSelectivity(RexNode)
statistic.- Parameters:
rel
- the relational expressionpredicate
- predicate whose selectivity is to be estimated againstrel
's output- Returns:
- estimated selectivity (between 0.0 and 1.0), or null if no reliable estimate can be determined
-
getUniqueKeys
Returns 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)
-
getUniqueKeys
Returns theBuiltInMetadata.UniqueKeys.getUniqueKeys(boolean)
statistic.- Parameters:
rel
- the relational expressionignoreNulls
- 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)
-
areRowsUnique
Returns whether the rows of a given relational expression are distinct. This is derived by applying theBuiltInMetadata.ColumnUniqueness.areColumnsUnique(org.apache.calcite.util.ImmutableBitSet, boolean)
statistic over all columns.- Parameters:
rel
- the relational expression- Returns:
- true or false depending on whether the rows are unique, or null if not enough information is available to make that determination
-
areColumnsUnique
Returns theBuiltInMetadata.ColumnUniqueness.areColumnsUnique(ImmutableBitSet, boolean)
statistic.- Parameters:
rel
- the relational expressioncolumns
- 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
-
areColumnsUnique
Returns theBuiltInMetadata.ColumnUniqueness.areColumnsUnique(ImmutableBitSet, boolean)
statistic.- Parameters:
rel
- the relational expressioncolumns
- column mask representing the subset of columns for which uniqueness will be determinedignoreNulls
- 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
-
collations
Returns 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
-
distribution
Returns 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
-
getPopulationSize
Returns theBuiltInMetadata.PopulationSize.getPopulationSize(ImmutableBitSet)
statistic.- Parameters:
rel
- the relational expressiongroupKey
- 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
-
getAverageRowSize
Returns theBuiltInMetadata.Size.averageRowSize()
statistic.- Parameters:
rel
- the relational expression- Returns:
- average size of a row, in bytes, or null if not known
-
getAverageColumnSizes
Returns 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
-
getAverageColumnSizesNotNull
AsgetAverageColumnSizes(org.apache.calcite.rel.RelNode)
but never returns a null list, only ever a list of nulls. -
isPhaseTransition
Returns 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
-
splitCount
Returns theBuiltInMetadata.Parallelism.splitCount()
statistic.- Parameters:
rel
- the relational expression- Returns:
- the number of distinct splits of the data, or null if not known
-
memory
Returns 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
-
cumulativeMemoryWithinPhase
Returns 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
-
cumulativeMemoryWithinPhaseSplit
Returns 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
-
getDistinctRowCount
Returns theBuiltInMetadata.DistinctRowCount.getDistinctRowCount(ImmutableBitSet, RexNode)
statistic.- Parameters:
rel
- the relational expressiongroupKey
- column mask representing group by columnspredicate
- pre-filtered predicates- Returns:
- distinct row count for groupKey, filtered by predicate, or null if no reliable estimate can be determined
-
getPulledUpPredicates
Returns theBuiltInMetadata.Predicates.getPredicates()
statistic.- Parameters:
rel
- the relational expression- Returns:
- Predicates that can be pulled above this RelNode
-
getAllPredicates
Returns theBuiltInMetadata.AllPredicates.getAllPredicates()
statistic.- Parameters:
rel
- the relational expression- Returns:
- All predicates within and below this RelNode
-
isVisibleInExplain
Returns theBuiltInMetadata.ExplainVisibility.isVisibleInExplain(SqlExplainLevel)
statistic.- Parameters:
rel
- the relational expressionexplainLevel
- level of detail- Returns:
- true for visible, false for invisible; if no metadata is available, defaults to true
-
getDistribution
Returns theBuiltInMetadata.Distribution.distribution()
statistic.- Parameters:
rel
- the relational expression- Returns:
- description of how the rows in the relational expression are physically distributed
-
getLowerBoundCost
Returns the lower bound cost of a RelNode.
-