Class RelOptUtil
RelOptUtil defines static utility methods for use in optimizing
RelNodes.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classVisitor which builds a bitmap of the inputs used by an expression.static classShuttle that finds the set of inputs that are used.static enumPolicies for handling two- and three-valued boolean logic.static classWalks an expression tree, converting the index of RexInputRefs based on some adjustment factor.static classExtension ofRelOptUtil.InputFinderwith optional subquery lookup.static enumWhat kind of sub-query.static classConverts types to descriptive strings.static classVisitor that finds all variables used in an expression. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends RelNode>
TadjustKeys(List<Integer> keys, int adjustment) Adjusts key values in a list by some fixed amount.static booleananalyzeSimpleEquiJoin(LogicalJoin join, int[] joinFieldOrdinals) Deprecated.static RexNodeandJoinFilters(RexBuilder rexBuilder, @Nullable RexNode left, @Nullable RexNode right) Ands two sets of join filters together, either of which can be null.static booleanareRowTypesEqual(RelDataType rowType1, RelDataType rowType2, boolean compareNames) static booleancheckProjAndChildInputs(Project project, boolean checkNames) Deprecated.static booleanclassifyFilters(RelNode joinRel, List<RexNode> filters, boolean pushInto, boolean pushLeft, boolean pushRight, List<RexNode> joinFilters, List<RexNode> leftFilters, List<RexNode> rightFilters) Classifies filters according to where they should be processed.static booleanclassifyFilters(RelNode joinRel, List<RexNode> filters, JoinRelType joinType, boolean pushInto, boolean pushLeft, boolean pushRight, List<RexNode> joinFilters, List<RexNode> leftFilters, List<RexNode> rightFilters) Deprecated.static RexCallcollapseExpandedIsNotDistinctFromExpr(RexCall rexCall, RexBuilder rexBuilder) Collapses an expanded version ofIS NOT DISTINCT FROMexpression.conjunctions(@Nullable RexNode rexPredicate) Returns a condition decomposed by AND.static booleanReturns whether relational expressiontargetoccurs within a relational expressionancestor.static RelNodecopyRelHints(RelNode originalRel, RelNode newRel) static RelNodecopyRelHints(RelNode originalRel, RelNode newRel, boolean filterHints) static ImmutableBitSetcorrelationColumns(CorrelationId id, RelNode rel) Finds which columns of a correlation variable are used within a relational expression.static intcountJoins(RelNode rootRel) Returns the number ofJoinnodes in a tree.static RelNodecreateCastRel(RelNode rel, RelDataType castRowType, boolean rename) Creates a projection which casts a rel's output to a desired row type.static RelNodecreateCastRel(RelNode rel, RelDataType castRowType, boolean rename, RelFactories.ProjectFactory projectFactory) Creates a projection which casts a rel's output to a desired row type.static RelNodecreateDistinctRel(RelNode rel) Deprecated.static RelDataTypecreateDmlRowType(SqlKind kind, RelDataTypeFactory typeFactory) Creates the row type descriptor for the result of a DML operation, which is a single column named ROWCOUNT of type BIGINT for INSERT; a single column named PLAN for EXPLAIN.static RexNodecreateEquiJoinCondition(RelNode left, List<Integer> leftKeys, RelNode right, List<Integer> rightKeys, RexBuilder rexBuilder) Builds an equi-join condition from a set of left and right keys.static RelNodecreateExistsPlan(RelOptCluster cluster, RelNode seekRel, @Nullable List<RexNode> conditions, @Nullable RexLiteral extraExpr, @Nullable String extraName) Deprecated.static RelOptUtil.ExistscreateExistsPlan(RelNode seekRel, RelOptUtil.SubQueryType subQueryType, RelOptUtil.Logic logic, boolean notIn) Deprecated.static RelOptUtil.ExistscreateExistsPlan(RelNode seekRel, RelOptUtil.SubQueryType subQueryType, RelOptUtil.Logic logic, boolean notIn, RelBuilder relBuilder) Creates a plan suitable for use inEXISTSorINstatements.static RelNodecreateFilter(RelNode child, Iterable<? extends RexNode> conditions) Creates a filter, using the default filter factory, or returns the original relational expression if the condition is trivial.static RelNodecreateFilter(RelNode child, Iterable<? extends RexNode> conditions, RelFactories.FilterFactory filterFactory) Creates a filter using the default factory, or returns the original relational expression if the condition is trivial.static RelNodecreateFilter(RelNode child, RexNode condition) Deprecated.static RelNodecreateFilter(RelNode child, RexNode condition, RelFactories.FilterFactory filterFactory) Deprecated.static RelNodecreateNullFilter(RelNode rel, Integer @Nullable [] fieldOrdinals) Deprecated.static RelNodecreateProject(RelFactories.ProjectFactory factory, RelNode child, List<Integer> posList) Creates a relational expression that projects the given fields of the input.static RelNodecreateProject(RelNode child, List<? extends RexNode> exprs, List<? extends @Nullable String> fieldNames, boolean optimize) Deprecated.static RelNodecreateProject(RelNode child, List<? extends RexNode> exprs, List<? extends @Nullable String> fieldNames, boolean optimize, RelBuilder relBuilder) Deprecated.static RelNodeDeprecated.static RelNodecreateProject(RelNode child, List<Integer> posList) Creates a relational expression that projects the given fields of the input.static RelNodecreateProject(RelNode child, List<Pair<RexNode, ? extends @Nullable String>> projectList, boolean optimize) Deprecated.static RelNodecreateProject(RelNode child, Mappings.TargetMapping mapping) Creates aLogicalProjectthat projects particular fields of its input, according to a mapping.static RelNodecreateProject(RelNode child, Mappings.TargetMapping mapping, RelFactories.ProjectFactory projectFactory) static RelNodecreateProjectJoinRel(List<Integer> outputProj, RelNode joinRel) Deprecated.static RelNodecreateRename(RelNode rel, List<? extends @Nullable String> fieldNames) Deprecated.static RelNodecreateRenameRel(RelDataType outputType, RelNode rel) Deprecated.static RelNodecreateSingleValueAggRel(RelOptCluster cluster, RelNode rel) Creates a LogicalAggregate that removes all duplicates from the result of an underlying relational expression.createSwappedJoinExprs(RelNode newJoin, Join origJoin, boolean origOrder) Creates projection expressions reflecting the swapping of a join's input.static voiddecomposeConjunction(@Nullable RexNode rexPredicate, List<RexNode> rexList) Decomposes a predicate into a list of expressions that are AND'ed together.static voidDecomposes a predicate into a list of expressions that are AND'ed together, and a list of expressions that are preceded by NOT.static voiddecomposeDisjunction(@Nullable RexNode rexPredicate, List<RexNode> rexList) Decomposes a predicate into a list of expressions that are OR'ed together.static List<RelDataTypeField>deduplicateColumns(List<RelDataTypeField> baseColumns, List<RelDataTypeField> extendedColumns) Returns the set of columns with unique names, with prior columns taking precedence over columns that appear later in the list.disjunctions(RexNode rexPredicate) Returns a condition decomposed by OR.static StringdumpPlan(String header, RelNode rel, boolean asXml, SqlExplainLevel detailLevel) Deprecated.static StringdumpPlan(String header, RelNode rel, SqlExplainFormat format, SqlExplainLevel detailLevel) Dumps a plan as a string.static StringdumpType(RelDataType type) static booleaneq(String desc1, RelDataType type1, String desc2, RelDataType type2, Litmus litmus) Returns whether two types are equal using 'equals'.static booleanequal(String desc1, RelDataType type1, String desc2, RelDataType type2, Litmus litmus) Returns whether two types are equal usingareRowTypesEqual(RelDataType, RelDataType, boolean).static booleanReturns whether two relational expressions have the same row-type.static booleaneqUpToNullability(boolean ignoreNullability, String desc1, RelDataType type1, String desc2, RelDataType type2, Litmus litmus) Returns whether two types are equal, perhaps ignoring nullability.Returns a list of all table qualified names used by this expression or its children.static List<RelOptTable>findAllTables(RelNode rel) Returns a list of all tables used by this expression or its children.static @Nullable RelOptTableReturns the relational table node fortableNameif it occurs within a relational expressionroototherwise an empty option is returned.static Set<RelOptTable>findTables(RelNode rel) Returns a set of tables used by this expression or its children.getAllFields(Aggregate aggregate) Gets all fields in an aggregate.getAllFields2(ImmutableBitSet groupSet, List<AggregateCall> aggCallList) Gets all fields in an aggregate.getColumnConstraints(ModifiableView modifiableViewTable, RelDataType targetRowType, RelDataTypeFactory typeFactory) Returns a mapping of the column ordinal in the underlying table to a column constraint of the modifiable view.static RelOptTable.ToRelContextgetContext(RelOptCluster cluster) Deprecated.static List<RelDataType>getFieldTypeList(RelDataType type) Returns a list of the types of the fields in a given struct type.static StringgetFullTypeDifferenceString(String sourceDesc, RelDataType sourceType, String targetDesc, RelDataType targetType) Returns the detailed difference of two types.static Set<CorrelationId>getVariablesSet(RelNode rel) Returns a list of variables set by a relational expression or its descendants.static List<CorrelationId>getVariablesSetAndUsed(RelNode rel0, RelNode rel1) Deprecated.static Set<CorrelationId>getVariablesUsed(List<RexSubQuery> subQueries) Returns the set of variables used by the given list of sub-queries and its descendants.static Set<CorrelationId>getVariablesUsed(RelNode rel) Returns the set of variables used by a relational expression or its descendants.static voidgo(RelVisitor visitor, RelNode p) Sets aRelVisitorgoing on a given relational expression, and returns the result.static voidDecomposes the WHERE clause of a view into predicates that constraint a column to a particular value.static RexNodeisDistinctFrom(RexBuilder rexBuilder, RexNode x, RexNode y, boolean neg) Returns a translation of theIS DISTINCT FROM(orIS NOT DISTINCT FROM) sql operator.static booleanDeprecated.static booleanWhether this node contains a limit specification.static booleanWhether this node contains an offset specification.static booleanWhether this node contains a sort specification.static booleanisPureLimit(RelNode rel) Whether this node is a limit without sort specification.static booleanisPureOrder(RelNode rel) Whether this node is a sort with neither limit nor offset specification.static booleannotContainsCorrelation(RelNode r, CorrelationId correlationId, Litmus litmus) Returns true, and callsLitmus.succeed()if a given relational expression does not contain a given correlation.static booleannotContainsWindowedAgg(Calc calc) Predicate for if aCalcdoes not contain windowed aggregates.static booleannotContainsWindowedAgg(Filter filter) Predicate for if aFilterdoes not contain windowed aggregates.static booleannotContainsWindowedAgg(Project project) Predicate for if aProjectdoes not contain windowed aggregates.static SqlOperatorop(SqlKind kind, SqlOperator operator) static Mappings.TargetMappingpermutation(List<RexNode> nodes, RelDataType inputRowType) Returns a permutation describing where output fields come from.static Mappings.TargetMappingpermutationIgnoreCast(List<RexNode> nodes, RelDataType inputRowType) Returns a permutation describing where output fields come from.static Mappings.TargetMappingpermutationPushDownProject(List<RexNode> nodes, RelDataType inputRowType, int sourceOffset, int targetOffset) Returns a permutation describing where the Project's fields come from after the Project is pushed down.static RelNodepermute(RelNode rel, Permutation permutation, @Nullable List<String> fieldNames) Creates a relational expression which permutes the output fields of a relational expression according to a permutation.static RelDataTypepermute(RelDataTypeFactory typeFactory, RelDataType rowType, Mapping mapping) Permutes a record type according to a mapping.static voidprojectJoinInputs(RelNode[] inputRels, List<RexNode> leftJoinKeys, List<RexNode> rightJoinKeys, int systemColCount, List<Integer> leftKeys, List<Integer> rightKeys, List<Integer> outputProj) Deprecated.static RelNodeprojectMapping(RelNode rel, Mapping mapping, @Nullable List<String> fieldNames, RelFactories.ProjectFactory projectFactory) Deprecated.static MultiJoinprojectMultiJoin(MultiJoin multiJoin, Project project) static RelNodepropagateRelHints(RelNode rel, boolean reset) Propagates the relational expression hints from root node to leaf node.static RelNodepropagateRelHints(RelNode originalRel, RelNode equiv) static RelNodepushDownJoinConditions(Join originalJoin) Deprecated.static RelNodepushDownJoinConditions(Join originalJoin, RelFactories.ProjectFactory projectFactory) Deprecated.static RelNodepushDownJoinConditions(Join originalJoin, RelBuilder relBuilder) Pushes down expressions in "equal" join condition.static RexNodepushFilterPastProject(RexNode filter, Project projRel) Deprecated.static RexNodepushPastCalc(RexNode node, Calc calc) Converts an expression that is based on the output fields of aCalcto an equivalent expression on the Calc's input fields.pushPastProject(List<? extends RexNode> nodes, Project project) Converts a list of expressions that are based on the output fields of aProjectto equivalent expressions on the Project's input fields.static RexNodepushPastProject(RexNode node, Project project) Converts an expression that is based on the output fields of aProjectto an equivalent expression on the Project's input fields.pushPastProjectUnlessBloat(List<? extends RexNode> nodes, Project project, int bloat) AspushPastProject(org.apache.calcite.rex.RexNode, org.apache.calcite.rel.core.Project), but returns null if the resulting expressions are significantly more complex.static @Nullable RexNodepushPastProjectUnlessBloat(RexNode node, Project project, int bloat) static voidstatic voidregisterAbstractRels(RelOptPlanner planner) Deprecated.static voidregisterAbstractRules(RelOptPlanner planner) static voidregisterDefaultRules(RelOptPlanner planner, boolean enableMaterializations, boolean enableBindable) static RelNoderenameIfNecessary(RelNode rel, RelDataType desiredRowType) Deprecated.static RelNodeWithin a relational expressionquery, replaces occurrences offindwithreplace.static RelNodereplaceInput(RelNode parent, int ordinal, RelNode newInput) Returns a shallow copy of a relational expression with a particular input replaced.static JoinRelTypesimplifyJoin(RelNode joinRel, com.google.common.collect.ImmutableList<RexNode> aboveFilters, JoinRelType joinType) Simplifies outer joins if filter above would reject nulls.static @Nullable RexNodesplitCorrelatedFilterCondition(Filter filter, List<RexNode> joinKeys, List<RexNode> correlatedJoinKeys, boolean extractCorrelatedFieldAccess) static @Nullable RexNodesplitCorrelatedFilterCondition(LogicalFilter filter, List<RexInputRef> joinKeys, List<RexNode> correlatedJoinKeys) Deprecated.static @Nullable RexNodesplitCorrelatedFilterCondition(LogicalFilter filter, List<RexNode> joinKeys, List<RexNode> correlatedJoinKeys, boolean extractCorrelatedFieldAccess) static voidsplitFilters(ImmutableBitSet childBitmap, @Nullable RexNode predicate, List<RexNode> pushable, List<RexNode> notPushable) Splits a filter into two lists, depending on whether or not the filter only references its child input.static RexNodesplitJoinCondition(List<RelDataTypeField> sysFieldList, List<RelNode> inputs, RexNode condition, List<List<RexNode>> joinKeys, @Nullable List<Integer> filterNulls, @Nullable List<SqlOperator> rangeOp) Splits out the equi-join (and optionally, a single non-equi) components of a join condition, and returns what's left.static RexNodesplitJoinCondition(List<RelDataTypeField> sysFieldList, RelNode leftRel, RelNode rightRel, RexNode condition, List<RexNode> leftJoinKeys, List<RexNode> rightJoinKeys, @Nullable List<Integer> filterNulls, @Nullable List<SqlOperator> rangeOp) Splits out the equi-join (and optionally, a single non-equi) components of a join condition, and returns what's left.static RexNodesplitJoinCondition(RelNode left, RelNode right, RexNode condition, List<Integer> leftKeys, List<Integer> rightKeys, @Nullable List<Boolean> filterNulls) Splits out the equi-join components of a join condition, and returns what's left.static voidsplitJoinCondition(RelNode left, RelNode right, RexNode condition, List<Integer> leftKeys, List<Integer> rightKeys, @Nullable List<Boolean> filterNulls, List<RexNode> nonEquiList) AssplitJoinCondition(RelNode, RelNode, RexNode, List, List, List), but writes non-equi conditions to a conjunctive list.static @PolyNull StringtoString(@PolyNull RelNode rel, SqlExplainLevel detailLevel, boolean expand) Converts a relational expression to a string; returns null if and only ifrelis null, returns expanded detail info forrelifexpandis true.static StringConverts a relational expression to a string, showing just basic attributes.static StringtoString(RelNode rel, SqlExplainLevel detailLevel) Converts a relational expression to a string, showing just basic attributes, and doesn't expand detail info forrel.static voidvalidateValueAgainstConstraint(SqlNode sourceValue, RexNode targetConstraint, Supplier<CalciteContextException> errorSupplier) Ensures that a source value does not violate the constraint of the target column.static voidverifyTypeEquivalence(RelNode originalRel, RelNode newRel, Object equivalenceClass) Verifies that a row type being added to an equivalence class matches the existing type, raising an assertion if this is not the case.
-
Field Details
-
EPSILON
public static final double EPSILON- See Also:
-
DEFAULT_BLOAT
public static final int DEFAULT_BLOAT -
FILTER_PREDICATE
Deprecated. -
PROJECT_PREDICATE
Deprecated. -
CALC_PREDICATE
Deprecated.
-
-
Constructor Details
-
RelOptUtil
public RelOptUtil()
-
-
Method Details
-
isPureLimit
Whether this node is a limit without sort specification. -
isPureOrder
Whether this node is a sort with neither limit nor offset specification. -
isLimit
Whether this node contains a limit specification. -
isOrder
Whether this node contains a sort specification. -
isOffset
Whether this node contains an offset specification. -
findTables
Returns a set of tables used by this expression or its children. -
findAllTables
Returns a list of all tables used by this expression or its children. -
findAllTableQualifiedNames
Returns a list of all table qualified names used by this expression or its children. -
getVariablesSet
Returns a list of variables set by a relational expression or its descendants. -
getVariablesSetAndUsed
Deprecated. -
getVariablesUsed
Returns the set of variables used by a relational expression or its descendants.The set may contain "duplicates" (variables with different ids that, when resolved, will reference the same source relational expression).
The item type is the same as
RexCorrelVariable.id. -
getVariablesUsed
Returns the set of variables used by the given list of sub-queries and its descendants.- Parameters:
subQueries- The sub-queries containing correlation variables- Returns:
- A list of correlation identifiers found within the sub-queries.
The type of the [CorrelationId] parameter corresponds to
RexCorrelVariable.id.
-
correlationColumns
Finds which columns of a correlation variable are used within a relational expression. -
notContainsCorrelation
Returns true, and callsLitmus.succeed()if a given relational expression does not contain a given correlation. -
go
Sets aRelVisitorgoing on a given relational expression, and returns the result. -
getFieldTypeList
Returns a list of the types of the fields in a given struct type. The list is immutable.- Parameters:
type- Struct type- Returns:
- List of field types
- See Also:
-
areRowTypesEqual
public static boolean areRowTypesEqual(RelDataType rowType1, RelDataType rowType2, boolean compareNames) -
verifyTypeEquivalence
public static void verifyTypeEquivalence(RelNode originalRel, RelNode newRel, Object equivalenceClass) Verifies that a row type being added to an equivalence class matches the existing type, raising an assertion if this is not the case.- Parameters:
originalRel- canonical rel for equivalence classnewRel- rel being added to equivalence classequivalenceClass- object representing equivalence class
-
propagateRelHints
Copy theRelHints fromoriginalReltonewRelif both of them areHintable.The two relational expressions are assumed as semantically equivalent, that means the hints should be attached to the relational expression that expects to have them.
Try to propagate the hints to the first relational expression that matches, this is needed because many planner rules would generate a sub-tree whose root rel type is different with the original matched rel.
For the worst case, there is no relational expression that can apply these hints, and the whole sub-tree would be visited. We add a protection here: if the visiting depth is over than 3, just returns, because there are rare cases the new created sub-tree has layers bigger than that.
This is a best effort, we do not know exactly how the nodes are transformed in all kinds of planner rules, so for some complex relational expressions, the hints would very probably lost.
This function is experimental and would change without any notes.
- Parameters:
originalRel- Original relational expressionequiv- New equivalent relational expression- Returns:
- A copy of
newRelwith attached qualified hints fromoriginalRel, ornewReldirectly if one of them are notHintable
-
propagateRelHints
Propagates the relational expression hints from root node to leaf node.- Parameters:
rel- The relational expressionreset- Flag saying if to reset the existing hints before the propagation- Returns:
- New relational expression with hints propagated
-
copyRelHints
Copy theRelHints fromoriginalReltonewRelif both of them areHintable.The hints would be attached directly(e.g. without any filtering).
- Parameters:
originalRel- Original relational expressionnewRel- New relational expression- Returns:
- A copy of
newRelwith attached hints fromoriginalRel, ornewReldirectly if one of them are notHintable
-
copyRelHints
Copy theRelHints fromoriginalReltonewRelif both of them areHintable.The hints would be filtered by the specified hint strategies if
filterHintsis true.- Parameters:
originalRel- Original relational expressionnewRel- New relational expressionfilterHints- Flag saying if to filter out unqualified hints fornewRel- Returns:
- A copy of
newRelwith attached hints fromoriginalRel, ornewReldirectly if one of them are notHintable
-
permutationIgnoreCast
public static Mappings.TargetMapping permutationIgnoreCast(List<RexNode> nodes, RelDataType inputRowType) Returns a permutation describing where output fields come from. In the returned map, value ofmap.getTargetOpt(i)isnif fieldiprojects input fieldnor applies a cast onn, -1 if it is another expression. -
permutation
Returns a permutation describing where output fields come from. In the returned map, value ofmap.getTargetOpt(i)isnif fieldiprojects input fieldn, -1 if it is an expression. -
permutationPushDownProject
public static Mappings.TargetMapping permutationPushDownProject(List<RexNode> nodes, RelDataType inputRowType, int sourceOffset, int targetOffset) Returns a permutation describing where the Project's fields come from after the Project is pushed down. -
createExistsPlan
@Deprecated public static RelNode createExistsPlan(RelOptCluster cluster, RelNode seekRel, @Nullable List<RexNode> conditions, @Nullable RexLiteral extraExpr, @Nullable String extraName) Deprecated. -
createExistsPlan
@Deprecated public static RelOptUtil.Exists createExistsPlan(RelNode seekRel, RelOptUtil.SubQueryType subQueryType, RelOptUtil.Logic logic, boolean notIn) Deprecated. -
createExistsPlan
public static RelOptUtil.Exists createExistsPlan(RelNode seekRel, RelOptUtil.SubQueryType subQueryType, RelOptUtil.Logic logic, boolean notIn, RelBuilder relBuilder) Creates a plan suitable for use inEXISTSorINstatements.- Parameters:
seekRel- A query rel, for example the resulting rel from 'select * from emp' or 'values (1,2,3)' or '('Foo', 34)'.subQueryType- Sub-query typelogic- Whether to use 2- or 3-valued boolean logicnotIn- Whether the operator is NOT INrelBuilder- Builder for relational expressions- Returns:
- A pair of a relational expression which outer joins a boolean condition column, and a numeric offset. The offset is 2 if column 0 is the number of rows and column 1 is the number of rows with not-null keys; 0 otherwise.
- See Also:
-
createRenameRel
Deprecated. -
createFilter
Deprecated. -
createFilter
@Deprecated public static RelNode createFilter(RelNode child, RexNode condition, RelFactories.FilterFactory filterFactory) Deprecated. -
createFilter
Creates a filter, using the default filter factory, or returns the original relational expression if the condition is trivial. -
createFilter
public static RelNode createFilter(RelNode child, Iterable<? extends RexNode> conditions, RelFactories.FilterFactory filterFactory) Creates a filter using the default factory, or returns the original relational expression if the condition is trivial. -
createNullFilter
Deprecated. -
createCastRel
Creates a projection which casts a rel's output to a desired row type.No need to create new projection if
relis already a project, instead, create a projection with the input ofreland the new cast expressions.The desired row type and the row type to be converted must have the same number of fields.
- Parameters:
rel- producer of rows to be convertedcastRowType- row type after castrename- if true, use field names from castRowType; if false, preserve field names from rel- Returns:
- conversion rel
-
createCastRel
public static RelNode createCastRel(RelNode rel, RelDataType castRowType, boolean rename, RelFactories.ProjectFactory projectFactory) Creates a projection which casts a rel's output to a desired row type.No need to create new projection if
relis already a project, instead, create a projection with the input ofreland the new cast expressions.The desired row type and the row type to be converted must have the same number of fields.
- Parameters:
rel- producer of rows to be convertedcastRowType- row type after castrename- if true, use field names from castRowType; if false, preserve field names from relprojectFactory- Project Factory- Returns:
- conversion rel
-
getAllFields
Gets all fields in an aggregate. -
getAllFields2
Gets all fields in an aggregate. -
createSingleValueAggRel
Creates a LogicalAggregate that removes all duplicates from the result of an underlying relational expression.- Parameters:
rel- underlying rel- Returns:
- rel implementing SingleValueAgg
-
createDistinctRel
Deprecated. -
analyzeSimpleEquiJoin
Deprecated. -
splitJoinCondition
public static RexNode splitJoinCondition(RelNode left, RelNode right, RexNode condition, List<Integer> leftKeys, List<Integer> rightKeys, @Nullable List<Boolean> filterNulls) Splits out the equi-join components of a join condition, and returns what's left. For example, given the conditionL.A = R.X AND L.B = L.C AND (L.D = 5 OR L.E = R.Y)returns
- leftKeys = {A}
- rightKeys = {X}
- rest = L.B = L.C AND (L.D = 5 OR L.E = R.Y)
- Parameters:
left- left input to joinright- right input to joincondition- join conditionleftKeys- The ordinals of the fields from the left input which are equi-join keysrightKeys- The ordinals of the fields from the right input which are equi-join keysfilterNulls- List of boolean values for each join key position indicating whether the operator filters out nulls or not. Value is true if the operator is EQUALS and false if the operator is IS NOT DISTINCT FROM (or an expanded version). IffilterNullsis null, only join conditions with EQUALS operators are considered equi-join components. Rest (including IS NOT DISTINCT FROM) are returned in remaining join condition.- Returns:
- remaining join filters that are not equijoins; may return a
RexLiteraltrue, but never null
-
splitJoinCondition
public static void splitJoinCondition(RelNode left, RelNode right, RexNode condition, List<Integer> leftKeys, List<Integer> rightKeys, @Nullable List<Boolean> filterNulls, List<RexNode> nonEquiList) AssplitJoinCondition(RelNode, RelNode, RexNode, List, List, List), but writes non-equi conditions to a conjunctive list. -
isEqui
Deprecated. -
splitJoinCondition
public static RexNode splitJoinCondition(List<RelDataTypeField> sysFieldList, RelNode leftRel, RelNode rightRel, RexNode condition, List<RexNode> leftJoinKeys, List<RexNode> rightJoinKeys, @Nullable List<Integer> filterNulls, @Nullable List<SqlOperator> rangeOp) Splits out the equi-join (and optionally, a single non-equi) components of a join condition, and returns what's left. Projection might be required by the caller to provide join keys that are not direct field references.- Parameters:
sysFieldList- list of system fieldsleftRel- left join inputrightRel- right join inputcondition- join conditionleftJoinKeys- The join keys from the left input which are equi-join keysrightJoinKeys- The join keys from the right input which are equi-join keysfilterNulls- The join key positions for which null values will not match. null values only match for the "is not distinct from" condition.rangeOp- if null, only locate equi-joins; otherwise, locate a single non-equi join predicate and return its operator in this list; join keys associated with the non-equi join predicate are at the end of the key lists returned- Returns:
- What's left, never null
-
splitJoinCondition
public static RexNode splitJoinCondition(List<RelDataTypeField> sysFieldList, List<RelNode> inputs, RexNode condition, List<List<RexNode>> joinKeys, @Nullable List<Integer> filterNulls, @Nullable List<SqlOperator> rangeOp) Splits out the equi-join (and optionally, a single non-equi) components of a join condition, and returns what's left. Projection might be required by the caller to provide join keys that are not direct field references.- Parameters:
sysFieldList- list of system fieldsinputs- join inputscondition- join conditionjoinKeys- The join keys from the inputs which are equi-join keysfilterNulls- The join key positions for which null values will not match. null values only match for the "is not distinct from" condition.rangeOp- if null, only locate equi-joins; otherwise, locate a single non-equi join predicate and return its operator in this list; join keys associated with the non-equi join predicate are at the end of the key lists returned- Returns:
- What's left, never null
-
createEquiJoinCondition
public static RexNode createEquiJoinCondition(RelNode left, List<Integer> leftKeys, RelNode right, List<Integer> rightKeys, RexBuilder rexBuilder) Builds an equi-join condition from a set of left and right keys. -
op
- Parameters:
kind- input kindoperator- default operator value- Returns:
- SqlOperator for the given kind
- See Also:
-
collapseExpandedIsNotDistinctFromExpr
Collapses an expanded version ofIS NOT DISTINCT FROMexpression.Helper method for
splitJoinCondition(RexBuilder, int, RexNode, List, List, List, List)andsplitJoinCondition(List, List, RexNode, List, List, List, List).If the given expr
rexCallcontains an expanded version ofIS NOT DISTINCT FROMfunction call, collapses it and return aIS NOT DISTINCT FROMfunction call.For example:
t1.key IS NOT DISTINCT FROM t2.keycan be rewritten in expanded form ast1.key = t2.key OR (t1.key IS NULL AND t2.key IS NULL).- Parameters:
rexCall- Function expression to try collapsingrexBuilder-RexBuilderinstance to create newRexCallinstances.- Returns:
- A function where all IS NOT DISTINCT FROM are collapsed.
-
projectJoinInputs
@Deprecated public static void projectJoinInputs(RelNode[] inputRels, List<RexNode> leftJoinKeys, List<RexNode> rightJoinKeys, int systemColCount, List<Integer> leftKeys, List<Integer> rightKeys, List<Integer> outputProj) Deprecated. -
createProjectJoinRel
Deprecated. -
registerAbstractRels
Deprecated. -
registerAbstractRules
-
registerAbstractRelationalRules
-
registerDefaultRules
public static void registerDefaultRules(RelOptPlanner planner, boolean enableMaterializations, boolean enableBindable) -
dumpPlan
public static String dumpPlan(String header, RelNode rel, SqlExplainFormat format, SqlExplainLevel detailLevel) Dumps a plan as a string.- Parameters:
header- Header to print before the plan. Ignored if the format is XMLrel- Relational expression to explainformat- Output formatdetailLevel- Detail level- Returns:
- Plan
-
dumpPlan
@Deprecated public static String dumpPlan(String header, RelNode rel, boolean asXml, SqlExplainLevel detailLevel) Deprecated. -
createDmlRowType
Creates the row type descriptor for the result of a DML operation, which is a single column named ROWCOUNT of type BIGINT for INSERT; a single column named PLAN for EXPLAIN.- Parameters:
kind- Kind of nodetypeFactory- factory to use for creating type descriptor- Returns:
- created type
-
eq
public static boolean eq(String desc1, RelDataType type1, String desc2, RelDataType type2, Litmus litmus) Returns whether two types are equal using 'equals'.- Parameters:
desc1- Description of first typetype1- First typedesc2- Description of second typetype2- Second typelitmus- What to do if an error is detected (types are not equal)- Returns:
- Whether the types are equal
-
eqUpToNullability
public static boolean eqUpToNullability(boolean ignoreNullability, String desc1, RelDataType type1, String desc2, RelDataType type2, Litmus litmus) Returns whether two types are equal, perhaps ignoring nullability.- Parameters:
ignoreNullability- If true the types must be equal ignoring the (top-level) nullability.desc1- Description of first typetype1- First typedesc2- Description of second typetype2- Second typelitmus- What to do if an error is detected (types are not equal)- Returns:
- Whether the types are equal
-
equal
public static boolean equal(String desc1, RelDataType type1, String desc2, RelDataType type2, Litmus litmus) Returns whether two types are equal usingareRowTypesEqual(RelDataType, RelDataType, boolean). Both types must not be null.- Parameters:
desc1- Description of role of first typetype1- First typedesc2- Description of role of second typetype2- Second typelitmus- Whether to assert if they are not equal- Returns:
- Whether the types are equal
-
getFullTypeDifferenceString
public static String getFullTypeDifferenceString(String sourceDesc, RelDataType sourceType, String targetDesc, RelDataType targetType) Returns the detailed difference of two types.- Parameters:
sourceDesc- description of role of source typesourceType- source typetargetDesc- description of role of target typetargetType- target type- Returns:
- the detailed difference of two types
-
equalType
public static boolean equalType(String desc0, RelNode rel0, String desc1, RelNode rel1, Litmus litmus) Returns whether two relational expressions have the same row-type. -
isDistinctFrom
Returns a translation of theIS DISTINCT FROM(orIS NOT DISTINCT FROM) sql operator.- Parameters:
neg- if false, returns a translation of IS NOT DISTINCT FROM
-
toString
Converts a relational expression to a string, showing just basic attributes. -
toString
Converts a relational expression to a string, showing just basic attributes, and doesn't expand detail info forrel. -
toString
public static @PolyNull String toString(@PolyNull RelNode rel, SqlExplainLevel detailLevel, boolean expand) Converts a relational expression to a string; returns null if and only ifrelis null, returns expanded detail info forrelifexpandis true. -
renameIfNecessary
Deprecated. -
dumpType
-
deduplicateColumns
public static List<RelDataTypeField> deduplicateColumns(List<RelDataTypeField> baseColumns, List<RelDataTypeField> extendedColumns) Returns the set of columns with unique names, with prior columns taking precedence over columns that appear later in the list. -
decomposeConjunction
Decomposes a predicate into a list of expressions that are AND'ed together.- Parameters:
rexPredicate- predicate to be analyzedrexList- list of decomposed RexNodes
-
decomposeConjunction
public static void decomposeConjunction(@Nullable RexNode rexPredicate, List<RexNode> rexList, List<RexNode> notList) Decomposes a predicate into a list of expressions that are AND'ed together, and a list of expressions that are preceded by NOT.For example,
a AND NOT b AND NOT (c and d) AND TRUE AND NOT FALSEreturnsrexList = [a], notList = [b, c AND d].TRUE and NOT FALSE expressions are ignored. FALSE and NOT TRUE expressions are placed on
rexListandnotListas other expressions.For example,
a AND TRUE AND NOT TRUEreturnsrexList = [a], notList = [TRUE].- Parameters:
rexPredicate- predicate to be analyzedrexList- list of decomposed RexNodes (except those with NOT)notList- list of decomposed RexNodes that were prefixed NOT
-
decomposeDisjunction
Decomposes a predicate into a list of expressions that are OR'ed together.- Parameters:
rexPredicate- predicate to be analyzedrexList- list of decomposed RexNodes
-
conjunctions
Returns a condition decomposed by AND.For example,
conjunctions(TRUE)returns the empty list;conjunctions(FALSE)returns list{FALSE}. -
disjunctions
Returns a condition decomposed by OR.For example,
disjunctions(FALSE)returns the empty list. -
andJoinFilters
public static RexNode andJoinFilters(RexBuilder rexBuilder, @Nullable RexNode left, @Nullable RexNode right) Ands two sets of join filters together, either of which can be null.- Parameters:
rexBuilder- rexBuilder to create AND expressionleft- filter on the left that the right will be AND'd toright- filter on the right- Returns:
- AND'd filter
- See Also:
-
inferViewPredicates
public static void inferViewPredicates(Map<Integer, RexNode> projectMap, List<RexNode> filters, RexNode constraint) Decomposes the WHERE clause of a view into predicates that constraint a column to a particular value.This method is key to the validation of a modifiable view. Columns that are constrained to a single value can be omitted from the SELECT clause of a modifiable view.
- Parameters:
projectMap- Mapping from column ordinal to the expression that populate that column, to be populated by this methodfilters- List of remaining filters, to be populated by this methodconstraint- Constraint to be analyzed
-
getColumnConstraints
public static Map<Integer,RexNode> getColumnConstraints(ModifiableView modifiableViewTable, RelDataType targetRowType, RelDataTypeFactory typeFactory) Returns a mapping of the column ordinal in the underlying table to a column constraint of the modifiable view.- Parameters:
modifiableViewTable- The modifiable view which has a constrainttargetRowType- The target type
-
validateValueAgainstConstraint
public static void validateValueAgainstConstraint(SqlNode sourceValue, RexNode targetConstraint, Supplier<CalciteContextException> errorSupplier) Ensures that a source value does not violate the constraint of the target column.- Parameters:
sourceValue- The insert value being validatedtargetConstraint- The constraint applied to sourceValue for validationerrorSupplier- The function to apply when validation fails
-
adjustKeys
Adjusts key values in a list by some fixed amount.- Parameters:
keys- list of key valuesadjustment- the amount to adjust the key values by- Returns:
- modified list
-
simplifyJoin
public static JoinRelType simplifyJoin(RelNode joinRel, com.google.common.collect.ImmutableList<RexNode> aboveFilters, JoinRelType joinType) Simplifies outer joins if filter above would reject nulls.- Parameters:
joinRel- JoinaboveFilters- Filters from abovejoinType- Join type, can not be inner join
-
classifyFilters
public static boolean classifyFilters(RelNode joinRel, List<RexNode> filters, boolean pushInto, boolean pushLeft, boolean pushRight, List<RexNode> joinFilters, List<RexNode> leftFilters, List<RexNode> rightFilters) Classifies filters according to where they should be processed. They either stay where they are, are pushed to the join (if they originated from above the join), or are pushed to one of the children. Filters that are pushed are added to list passed in as input parameters.- Parameters:
joinRel- join nodefilters- filters to be classifiedpushInto- whether filters can be pushed into the joinpushLeft- true if filters can be pushed to the leftpushRight- true if filters can be pushed to the rightjoinFilters- list of filters to push to the joinleftFilters- list of filters to push to the left childrightFilters- list of filters to push to the right child- Returns:
- whether at least one filter was pushed
-
classifyFilters
@Deprecated public static boolean classifyFilters(RelNode joinRel, List<RexNode> filters, JoinRelType joinType, boolean pushInto, boolean pushLeft, boolean pushRight, List<RexNode> joinFilters, List<RexNode> leftFilters, List<RexNode> rightFilters) Classifies filters according to where they should be processed. They either stay where they are, are pushed to the join (if they originated from above the join), or are pushed to one of the children. Filters that are pushed are added to list passed in as input parameters.- Parameters:
joinRel- join nodefilters- filters to be classifiedjoinType- join typepushInto- whether filters can be pushed into the ON clausepushLeft- true if filters can be pushed to the leftpushRight- true if filters can be pushed to the rightjoinFilters- list of filters to push to the joinleftFilters- list of filters to push to the left childrightFilters- list of filters to push to the right child- Returns:
- whether at least one filter was pushed
-
splitFilters
public static void splitFilters(ImmutableBitSet childBitmap, @Nullable RexNode predicate, List<RexNode> pushable, List<RexNode> notPushable) Splits a filter into two lists, depending on whether or not the filter only references its child input.- Parameters:
childBitmap- Fields in the childpredicate- filters that will be splitpushable- returns the list of filters that can be pushed to the child inputnotPushable- returns the list of filters that cannot be pushed to the child input
-
checkProjAndChildInputs
Deprecated. -
createSwappedJoinExprs
public static List<RexNode> createSwappedJoinExprs(RelNode newJoin, Join origJoin, boolean origOrder) Creates projection expressions reflecting the swapping of a join's input.- Parameters:
newJoin- the RelNode corresponding to the join with its inputs swappedorigJoin- original LogicalJoinorigOrder- if true, create the projection expressions to reflect the original (pre-swapped) join projection; otherwise, create the projection to reflect the order of the swapped projection- Returns:
- array of expression representing the swapped join inputs
-
pushFilterPastProject
Deprecated. -
pushPastProject
Converts an expression that is based on the output fields of aProjectto an equivalent expression on the Project's input fields.- Parameters:
node- The expression to be convertedproject- Project underneath the expression- Returns:
- converted expression
-
pushPastProject
Converts a list of expressions that are based on the output fields of aProjectto equivalent expressions on the Project's input fields.- Parameters:
nodes- The expressions to be convertedproject- Project underneath the expression- Returns:
- converted expressions
-
pushPastProjectUnlessBloat
-
pushPastProjectUnlessBloat
public static @Nullable List<RexNode> pushPastProjectUnlessBloat(List<? extends RexNode> nodes, Project project, int bloat) AspushPastProject(org.apache.calcite.rex.RexNode, org.apache.calcite.rel.core.Project), but returns null if the resulting expressions are significantly more complex.- Parameters:
bloat- Maximum allowable increase in complexity
-
pushPastCalc
Converts an expression that is based on the output fields of aCalcto an equivalent expression on the Calc's input fields.- Parameters:
node- The expression to be convertedcalc- Calc underneath the expression- Returns:
- converted expression
-
projectMultiJoin
Creates a newMultiJointo reflect projection references from aProjectthat is on top of theMultiJoin.- Parameters:
multiJoin- the original MultiJoinproject- the Project on top of the MultiJoin- Returns:
- the new MultiJoin
-
addTrait
-
replaceInput
Returns a shallow copy of a relational expression with a particular input replaced. -
createProject
Creates aLogicalProjectthat projects particular fields of its input, according to a mapping. -
createProject
public static RelNode createProject(RelNode child, Mappings.TargetMapping mapping, RelFactories.ProjectFactory projectFactory) -
findTable
Returns the relational table node fortableNameif it occurs within a relational expressionroototherwise an empty option is returned. -
contains
Returns whether relational expressiontargetoccurs within a relational expressionancestor. -
replace
Within a relational expressionquery, replaces occurrences offindwithreplace. -
getContext
Deprecated. -
countJoins
Returns the number ofJoinnodes in a tree. -
permute
public static RelDataType permute(RelDataTypeFactory typeFactory, RelDataType rowType, Mapping mapping) Permutes a record type according to a mapping. -
createProject
@Deprecated public static RelNode createProject(RelNode child, List<? extends RexNode> exprList, List<String> fieldNameList) Deprecated. -
createProject
@Deprecated public static RelNode createProject(RelNode child, List<Pair<RexNode, ? extends @Nullable String>> projectList, boolean optimize) Deprecated. -
createProject
Creates a relational expression that projects the given fields of the input.Optimizes if the fields are the identity projection.
- Parameters:
child- Input relational expressionposList- Source of each projected field- Returns:
- Relational expression that projects given fields
-
createProject
@Deprecated public static RelNode createProject(RelNode child, List<? extends RexNode> exprs, List<? extends @Nullable String> fieldNames, boolean optimize) Deprecated. -
createProject
@Deprecated public static RelNode createProject(RelNode child, List<? extends RexNode> exprs, List<? extends @Nullable String> fieldNames, boolean optimize, RelBuilder relBuilder) Deprecated. -
createRename
@Deprecated public static RelNode createRename(RelNode rel, List<? extends @Nullable String> fieldNames) Deprecated. -
permute
public static RelNode permute(RelNode rel, Permutation permutation, @Nullable List<String> fieldNames) Creates a relational expression which permutes the output fields of a relational expression according to a permutation.Optimizations:
- If the relational expression is a
LogicalCalcorLogicalProjectthat is already acting as a permutation, combines the new permutation with the old; - If the permutation is the identity, returns the original relational expression.
If a permutation is combined with its inverse, these optimizations would combine to remove them both.
- Parameters:
rel- Relational expressionpermutation- Permutation to apply to fieldsfieldNames- Field names; if null, or if a particular entry is null, the name of the permuted field is used- Returns:
- relational expression which permutes its input fields
- If the relational expression is a
-
createProject
public static RelNode createProject(RelFactories.ProjectFactory factory, RelNode child, List<Integer> posList) Creates a relational expression that projects the given fields of the input.Optimizes if the fields are the identity projection.
- Parameters:
factory- ProjectFactorychild- Input relational expressionposList- Source of each projected field- Returns:
- Relational expression that projects given fields
-
projectMapping
@Deprecated public static RelNode projectMapping(RelNode rel, Mapping mapping, @Nullable List<String> fieldNames, RelFactories.ProjectFactory projectFactory) Deprecated. -
notContainsWindowedAgg
Predicate for if aCalcdoes not contain windowed aggregates. -
notContainsWindowedAgg
Predicate for if aFilterdoes not contain windowed aggregates. -
notContainsWindowedAgg
Predicate for if aProjectdoes not contain windowed aggregates. -
pushDownJoinConditions
Pushes down expressions in "equal" join condition.For example, given "emp JOIN dept ON emp.deptno + 1 = dept.deptno", adds a project above "emp" that computes the expression "emp.deptno + 1". The resulting join condition is a simple combination of AND, equals, and input fields, plus the remaining non-equal conditions.
- Parameters:
originalJoin- Join whose condition is to be pushed downrelBuilder- Factory to create project operator
-
pushDownJoinConditions
Deprecated. -
pushDownJoinConditions
@Deprecated public static RelNode pushDownJoinConditions(Join originalJoin, RelFactories.ProjectFactory projectFactory) Deprecated.
-
classifyFilters(RelNode, List, boolean, boolean, boolean, List, List, List)