Class RelMdExpressionLineage
- java.lang.Object
-
- org.apache.calcite.rel.metadata.RelMdExpressionLineage
-
- All Implemented Interfaces:
MetadataHandler<BuiltInMetadata.ExpressionLineage>
public class RelMdExpressionLineage extends java.lang.Object implements MetadataHandler<BuiltInMetadata.ExpressionLineage>
Default implementation ofRelMetadataQuery.getExpressionLineage(org.apache.calcite.rel.RelNode, org.apache.calcite.rex.RexNode)
for the standard logical algebra.The goal of this provider is to infer the lineage for the given expression.
The output expressions might contain references to columns produced by
TableScan
operators (RexTableInputRef
). In turn, each TableScan operator is identified uniquely by aRexTableInputRef.RelTableRef
containing its qualified name and an identifier.If the lineage cannot be inferred, we return null.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
RelMdExpressionLineage.RexReplacer
Replaces expressions with their equivalences.
-
Field Summary
Fields Modifier and Type Field Description static RelMetadataProvider
SOURCE
-
Constructor Summary
Constructors Modifier Constructor Description protected
RelMdExpressionLineage()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static java.util.Set<RexNode>
createAllPossibleExpressions(RexBuilder rexBuilder, RexNode expr, java.util.Map<RexInputRef,java.util.Set<RexNode>> mapping)
Given an expression, it will create all equivalent expressions resulting from replacing all possible combinations of references in the mapping by the corresponding expressions.private static java.util.Set<RexNode>
createAllPossibleExpressions(RexBuilder rexBuilder, RexNode expr, ImmutableBitSet predFieldsUsed, java.util.Map<RexInputRef,java.util.Set<RexNode>> mapping, java.util.Map<RexInputRef,RexNode> singleMapping)
private static void
createExpressions(RexBuilder rexBuilder, RexNode expr, ImmutableBitSet predFieldsUsed, java.util.Map<RexInputRef,java.util.Set<RexNode>> mapping, java.util.Map<RexInputRef,RexNode> singleMapping, java.util.Set<RexNode> result)
private static ImmutableBitSet
extractInputRefs(RexNode expr)
MetadataDef<BuiltInMetadata.ExpressionLineage>
getDef()
java.util.Set<RexNode>
getExpressionLineage(HepRelVertex rel, RelMetadataQuery mq, RexNode outputExpression)
java.util.Set<RexNode>
getExpressionLineage(RelSubset rel, RelMetadataQuery mq, RexNode outputExpression)
java.util.Set<RexNode>
getExpressionLineage(Aggregate rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage fromAggregate
.java.util.Set<RexNode>
getExpressionLineage(Exchange rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage from Exchange.java.util.Set<RexNode>
getExpressionLineage(Filter rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage from Filter.java.util.Set<RexNode>
getExpressionLineage(Join rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage fromJoin
.java.util.Set<RexNode>
getExpressionLineage(Project rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage from Project.java.util.Set<RexNode>
getExpressionLineage(Sort rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage from Sort.java.util.Set<RexNode>
getExpressionLineage(TableScan rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage fromTableScan
.java.util.Set<RexNode>
getExpressionLineage(Union rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage fromUnion
.java.util.Set<RexNode>
getExpressionLineage(RelNode rel, RelMetadataQuery mq, RexNode outputExpression)
-
-
-
Field Detail
-
SOURCE
public static final RelMetadataProvider SOURCE
-
-
Method Detail
-
getDef
public MetadataDef<BuiltInMetadata.ExpressionLineage> getDef()
- Specified by:
getDef
in interfaceMetadataHandler<BuiltInMetadata.ExpressionLineage>
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(RelNode rel, RelMetadataQuery mq, RexNode outputExpression)
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(HepRelVertex rel, RelMetadataQuery mq, RexNode outputExpression)
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(RelSubset rel, RelMetadataQuery mq, RexNode outputExpression)
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(TableScan rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage fromTableScan
.We extract the fields referenced by the expression and we express them using
RexTableInputRef
.
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(Aggregate rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage fromAggregate
.If the expression references grouping sets or aggregate function results, we cannot extract the lineage and we return null.
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(Join rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage fromJoin
.We only extract the lineage for INNER joins.
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(Union rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage fromUnion
.For Union operator, we might be able to extract multiple origins for the references in the given expression.
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(Project rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage from Project.
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(Filter rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage from Filter.
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(Sort rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage from Sort.
-
getExpressionLineage
public java.util.Set<RexNode> getExpressionLineage(Exchange rel, RelMetadataQuery mq, RexNode outputExpression)
Expression lineage from Exchange.
-
createAllPossibleExpressions
@Nullable protected static java.util.Set<RexNode> createAllPossibleExpressions(RexBuilder rexBuilder, RexNode expr, java.util.Map<RexInputRef,java.util.Set<RexNode>> mapping)
Given an expression, it will create all equivalent expressions resulting from replacing all possible combinations of references in the mapping by the corresponding expressions.- Parameters:
rexBuilder
- rexBuilderexpr
- expressionmapping
- mapping- Returns:
- set of resulting expressions equivalent to the input expression
-
createAllPossibleExpressions
private static java.util.Set<RexNode> createAllPossibleExpressions(RexBuilder rexBuilder, RexNode expr, ImmutableBitSet predFieldsUsed, java.util.Map<RexInputRef,java.util.Set<RexNode>> mapping, java.util.Map<RexInputRef,RexNode> singleMapping)
-
createExpressions
private static void createExpressions(RexBuilder rexBuilder, RexNode expr, ImmutableBitSet predFieldsUsed, java.util.Map<RexInputRef,java.util.Set<RexNode>> mapping, java.util.Map<RexInputRef,RexNode> singleMapping, java.util.Set<RexNode> result)
-
extractInputRefs
private static ImmutableBitSet extractInputRefs(RexNode expr)
-
-