public abstract class RelOptUtil
extends java.lang.Object
RelOptUtil
defines static utility methods for use in optimizing
RelNode
s.Modifier and Type | Class and Description |
---|---|
private static class |
RelOptUtil.CorrelationCollector
Shuttle that finds correlation variables inside a given relational
expression, including those that are inside
sub-queries . |
static class |
RelOptUtil.Exists
|
static class |
RelOptUtil.InputFinder
Visitor which builds a bitmap of the inputs used by an expression.
|
static class |
RelOptUtil.InputReferencedVisitor
Shuttle that finds the set of inputs that are used.
|
static class |
RelOptUtil.Logic
Policies for handling two- and three-valued boolean logic.
|
static class |
RelOptUtil.RexInputConverter
Walks an expression tree, converting the index of RexInputRefs based on
some adjustment factor.
|
(package private) static class |
RelOptUtil.Side
Categorizes whether a bit set contains bits left and right of a
line.
|
static class |
RelOptUtil.SubQueryType
What kind of sub-query.
|
static class |
RelOptUtil.TypeDumper
Converts types to descriptive strings.
|
private static class |
RelOptUtil.VariableSetVisitor
Visitor that finds all variables used but not stopped in an expression.
|
static class |
RelOptUtil.VariableUsedVisitor
Visitor that finds all variables used in an expression.
|
Modifier and Type | Field and Description |
---|---|
(package private) static boolean |
B |
static com.google.common.base.Predicate<Calc> |
CALC_PREDICATE
Deprecated.
|
static double |
EPSILON |
static com.google.common.base.Predicate<Filter> |
FILTER_PREDICATE
Deprecated.
|
static com.google.common.base.Predicate<Project> |
PROJECT_PREDICATE
Deprecated.
|
Constructor and Description |
---|
RelOptUtil() |
Modifier and Type | Method and Description |
---|---|
private static void |
addJoinKey(java.util.List<RexNode> joinKeyList,
RexNode key,
boolean preserveLastElementInList) |
static <T extends RelNode> |
addTrait(T rel,
RelTrait trait) |
static java.util.List<java.lang.Integer> |
adjustKeys(java.util.List<java.lang.Integer> keys,
int adjustment)
Adjusts key values in a list by some fixed amount.
|
static boolean |
analyzeSimpleEquiJoin(LogicalJoin join,
int[] joinFieldOrdinals)
Deprecated.
|
static RexNode |
andJoinFilters(RexBuilder rexBuilder,
RexNode left,
RexNode right)
Ands two sets of join filters together, either of which can be null.
|
static boolean |
areRowTypesEqual(RelDataType rowType1,
RelDataType rowType2,
boolean compareNames) |
static boolean |
checkProjAndChildInputs(Project project,
boolean checkNames)
Deprecated.
|
static boolean |
classifyFilters(RelNode joinRel,
java.util.List<RexNode> filters,
JoinRelType joinType,
boolean pushInto,
boolean pushLeft,
boolean pushRight,
java.util.List<RexNode> joinFilters,
java.util.List<RexNode> leftFilters,
java.util.List<RexNode> rightFilters)
Classifies filters according to where they should be processed.
|
static RexCall |
collapseExpandedIsNotDistinctFromExpr(RexCall call,
RexBuilder rexBuilder)
Collapses an expanded version of
IS NOT DISTINCT FROM expression. |
static java.util.List<RexNode> |
conjunctions(RexNode rexPredicate)
Returns a condition decomposed by AND.
|
static boolean |
contains(RelNode ancestor,
RelNode target)
Returns whether relational expression
target occurs within a
relational expression ancestor . |
private static boolean |
containsGet(RexNode node) |
static boolean |
containsMultisetOrWindowedAgg(Calc calc)
Predicate for whether a
Calc contains multisets or windowed
aggregates. |
static boolean |
containsMultisetOrWindowedAgg(Filter filter)
Predicate for whether a
Filter contains multisets or windowed
aggregates. |
static boolean |
containsMultisetOrWindowedAgg(Project project)
Predicate for whether a
Project contains multisets or windowed
aggregates. |
private static boolean |
containsNullableFields(RelNode r)
Determines whether any of the fields in a given relational expression may
contain null values, taking into account constraints on the field types and
also deduced predicates.
|
static ImmutableBitSet |
correlationColumns(CorrelationId id,
RelNode rel)
Finds which columns of a correlation variable are used within a
relational expression.
|
static int |
countJoins(RelNode rootRel)
Returns the number of
Join nodes in a
tree. |
static RelNode |
createCastRel(RelNode rel,
RelDataType castRowType,
boolean rename)
Creates a projection which casts a rel's output to a desired row type.
|
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.
|
static RelNode |
createDistinctRel(RelNode rel)
Deprecated.
|
static RelDataType |
createDmlRowType(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 RexNode |
createEquiJoinCondition(RelNode left,
java.util.List<java.lang.Integer> leftKeys,
RelNode right,
java.util.List<java.lang.Integer> rightKeys,
RexBuilder rexBuilder)
Builds an equi-join condition from a set of left and right keys.
|
static RelOptUtil.Exists |
createExistsPlan(RelNode seekRel,
RelOptUtil.SubQueryType subQueryType,
RelOptUtil.Logic logic,
boolean notIn)
Deprecated.
|
static RelOptUtil.Exists |
createExistsPlan(RelNode seekRel,
RelOptUtil.SubQueryType subQueryType,
RelOptUtil.Logic logic,
boolean notIn,
RelBuilder relBuilder)
Creates a plan suitable for use in
EXISTS or IN
statements. |
static RelNode |
createExistsPlan(RelOptCluster cluster,
RelNode seekRel,
java.util.List<RexNode> conditions,
RexLiteral extraExpr,
java.lang.String extraName)
Deprecated.
|
static RelNode |
createFilter(RelNode child,
java.lang.Iterable<? extends RexNode> conditions)
Creates a filter, using the default filter factory,
or returns the original relational expression if the
condition is trivial.
|
static RelNode |
createFilter(RelNode child,
java.lang.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 RelNode |
createFilter(RelNode child,
RexNode condition)
Deprecated.
|
static RelNode |
createFilter(RelNode child,
RexNode condition,
RelFactories.FilterFactory filterFactory)
Deprecated.
|
static RelNode |
createNullFilter(RelNode rel,
java.lang.Integer[] fieldOrdinals)
Deprecated.
|
static RelNode |
createProject(RelFactories.ProjectFactory factory,
RelNode child,
java.util.List<java.lang.Integer> posList)
Creates a relational expression that projects the given fields of the
input.
|
static RelNode |
createProject(RelNode child,
java.util.List<? extends RexNode> exprList,
java.util.List<java.lang.String> fieldNameList)
Deprecated.
|
static RelNode |
createProject(RelNode child,
java.util.List<? extends RexNode> exprs,
java.util.List<java.lang.String> fieldNames,
boolean optimize)
Deprecated.
|
static RelNode |
createProject(RelNode child,
java.util.List<? extends RexNode> exprs,
java.util.List<java.lang.String> fieldNames,
boolean optimize,
RelBuilder relBuilder)
Deprecated.
|
static RelNode |
createProject(RelNode child,
java.util.List<java.lang.Integer> posList)
Creates a relational expression that projects the given fields of the
input.
|
static RelNode |
createProject(RelNode child,
java.util.List<Pair<RexNode,java.lang.String>> projectList,
boolean optimize)
Deprecated.
|
static RelNode |
createProject(RelNode child,
Mappings.TargetMapping mapping)
Creates a
LogicalProject that
projects particular fields of its input, according to a mapping. |
static RelNode |
createProject(RelNode child,
Mappings.TargetMapping mapping,
RelFactories.ProjectFactory projectFactory) |
static RelNode |
createProjectJoinRel(java.util.List<java.lang.Integer> outputProj,
RelNode joinRel)
Deprecated.
|
static RelNode |
createRename(RelNode rel,
java.util.List<java.lang.String> fieldNames)
Deprecated.
|
static RelNode |
createRenameRel(RelDataType outputType,
RelNode rel)
Deprecated.
|
static RelNode |
createSingleValueAggRel(RelOptCluster cluster,
RelNode rel)
Creates a LogicalAggregate that removes all duplicates from the result of
an underlying relational expression.
|
static java.util.List<RexNode> |
createSwappedJoinExprs(RelNode newJoin,
Join origJoin,
boolean origOrder)
Creates projection expressions reflecting the swapping of a join's input.
|
static void |
decomposeConjunction(RexNode rexPredicate,
java.util.List<RexNode> rexList)
Decomposes a predicate into a list of expressions that are AND'ed
together.
|
static void |
decomposeConjunction(RexNode rexPredicate,
java.util.List<RexNode> rexList,
java.util.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.
|
static void |
decomposeDisjunction(RexNode rexPredicate,
java.util.List<RexNode> rexList)
Decomposes a predicate into a list of expressions that are OR'ed
together.
|
static java.util.List<RelDataTypeField> |
deduplicateColumns(java.util.List<RelDataTypeField> baseColumns,
java.util.List<RelDataTypeField> extendedColumns)
Returns the set of columns with unique names, with prior columns taking
precedence over columns that appear later in the list.
|
static java.util.List<RexNode> |
disjunctions(RexNode rexPredicate)
Returns a condition decomposed by OR.
|
private static RexCall |
doCollapseExpandedIsNotDistinctFrom(RexBuilder rexBuilder,
RexCall call,
RexCall ifNull0Call,
RexCall ifNull1Call,
RexCall equalsCall) |
private static RexCall |
doCollapseExpandedIsNotDistinctFromCaseExpr(RexCall call,
RexBuilder rexBuilder) |
private static RexCall |
doCollapseExpandedIsNotDistinctFromOrExpr(RexCall call,
RexBuilder rexBuilder) |
static java.lang.String |
dumpPlan(java.lang.String header,
RelNode rel,
boolean asXml,
SqlExplainLevel detailLevel)
Deprecated.
|
static java.lang.String |
dumpPlan(java.lang.String header,
RelNode rel,
SqlExplainFormat format,
SqlExplainLevel detailLevel)
Dumps a plan as a string.
|
static java.lang.String |
dumpType(RelDataType type) |
static boolean |
eq(java.lang.String desc1,
RelDataType type1,
java.lang.String desc2,
RelDataType type2,
Litmus litmus)
Returns whether two types are equal using '='.
|
static boolean |
equal(java.lang.String desc1,
RelDataType type1,
java.lang.String desc2,
RelDataType type2,
Litmus litmus)
Returns whether two types are equal using
areRowTypesEqual(RelDataType, RelDataType, boolean) . |
static boolean |
equalType(java.lang.String desc0,
RelNode rel0,
java.lang.String desc1,
RelNode rel1,
Litmus litmus)
Returns whether two relational expressions have the same row-type.
|
static java.util.List<java.lang.String> |
findAllTableQualifiedNames(RelNode rel)
Returns a list of all table qualified names used by this expression
or its children.
|
static java.util.List<RelOptTable> |
findAllTables(RelNode rel)
Returns a list of all tables used by this expression or its children
|
static java.util.Set<RelOptTable> |
findTables(RelNode rel)
Returns a set of tables used by this expression or its children
|
private static void |
fix(java.util.List<RexNode> operands,
int before,
int after) |
static boolean |
forceEquiJoin(Join join)
Check if it is the join whose condition is based on column equality,
this mostly depends on the physical implementation of the join.
|
static java.util.Set<java.lang.Integer> |
getAllFields(Aggregate aggregate)
Gets all fields in an aggregate.
|
static java.util.Map<java.lang.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.
|
static RelOptTable.ToRelContext |
getContext(RelOptCluster cluster)
Deprecated.
|
static java.util.List<RelDataType> |
getFieldTypeList(RelDataType type)
Returns a list of the types of the fields in a given struct type.
|
static java.util.Set<CorrelationId> |
getVariablesSet(RelNode rel)
Returns a list of variables set by a relational expression or its
descendants.
|
static java.util.List<CorrelationId> |
getVariablesSetAndUsed(RelNode rel0,
RelNode rel1)
Deprecated.
|
static java.util.Set<CorrelationId> |
getVariablesUsed(RelNode rel)
Returns a set of variables used by a relational expression or its
descendants.
|
static void |
go(RelVisitor visitor,
RelNode p)
Sets a
RelVisitor going on a given relational expression, and
returns the result. |
static void |
inferViewPredicates(java.util.Map<java.lang.Integer,RexNode> projectMap,
java.util.List<RexNode> filters,
RexNode constraint)
Decomposes the WHERE clause of a view into predicates that constraint
a column to a particular value.
|
static RexNode |
isDistinctFrom(RexBuilder rexBuilder,
RexNode x,
RexNode y,
boolean neg)
Returns a translation of the
IS DISTINCT FROM (or IS
NOT DISTINCT FROM ) sql operator. |
private static RexNode |
isDistinctFromInternal(RexBuilder rexBuilder,
RexNode x,
RexNode y,
boolean neg) |
static boolean |
isEqui(RelNode left,
RelNode right,
RexNode condition)
Deprecated.
|
static boolean |
isLimit(RelNode rel)
Whether this node contains a limit specification.
|
static boolean |
isOrder(RelNode rel)
Whether this node contains a sort specification.
|
static boolean |
isPureLimit(RelNode rel)
Whether this node is a limit without sort specification.
|
static boolean |
isPureOrder(RelNode rel)
Whether this node is a sort without limit specification.
|
static boolean |
notContainsCorrelation(RelNode r,
CorrelationId correlationId,
Litmus litmus)
Returns true, and calls
Litmus.succeed() if a given relational
expression does not contain a given correlation. |
static SqlOperator |
op(SqlKind kind,
SqlOperator operator) |
static Mappings.TargetMapping |
permutation(java.util.List<RexNode> nodes,
RelDataType inputRowType)
Returns a permutation describing where output fields come from.
|
static Mappings.TargetMapping |
permutationIgnoreCast(java.util.List<RexNode> nodes,
RelDataType inputRowType)
Returns a permutation describing where output fields come from.
|
static RelDataType |
permute(RelDataTypeFactory typeFactory,
RelDataType rowType,
Mapping mapping)
Permutes a record type according to a mapping.
|
static RelNode |
permute(RelNode rel,
Permutation permutation,
java.util.List<java.lang.String> fieldNames)
Creates a relational expression which permutes the output fields of a
relational expression according to a permutation.
|
static void |
projectJoinInputs(RelNode[] inputRels,
java.util.List<RexNode> leftJoinKeys,
java.util.List<RexNode> rightJoinKeys,
int systemColCount,
java.util.List<java.lang.Integer> leftKeys,
java.util.List<java.lang.Integer> rightKeys,
java.util.List<java.lang.Integer> outputProj)
Deprecated.
|
static RelNode |
projectMapping(RelNode rel,
Mapping mapping,
java.util.List<java.lang.String> fieldNames,
RelFactories.ProjectFactory projectFactory)
Deprecated.
|
static MultiJoin |
projectMultiJoin(MultiJoin multiJoin,
Project project)
|
private static RexNode |
pushDownEqualJoinConditions(RexNode condition,
int leftCount,
int rightCount,
java.util.List<RexNode> extraLeftExprs,
java.util.List<RexNode> extraRightExprs,
RexBuilder builder)
Pushes down parts of a join condition.
|
static RelNode |
pushDownJoinConditions(Join originalJoin)
Deprecated.
|
static RelNode |
pushDownJoinConditions(Join originalJoin,
RelBuilder relBuilder)
Pushes down expressions in "equal" join condition.
|
private static RelNode |
pushDownJoinConditions(Join originalJoin,
RelBuilderFactory relBuilderFactory) |
static RelNode |
pushDownJoinConditions(Join originalJoin,
RelFactories.ProjectFactory projectFactory)
Deprecated.
|
static RexNode |
pushFilterPastProject(RexNode filter,
Project projRel)
Deprecated.
|
static java.util.List<RexNode> |
pushPastProject(java.util.List<? extends RexNode> nodes,
Project project)
Converts a list of expressions that are based on the output fields of a
Project to equivalent expressions on the Project's
input fields. |
static RexNode |
pushPastProject(RexNode node,
Project project)
Converts an expression that is based on the output fields of a
Project to an equivalent expression on the Project's
input fields. |
private static RexShuttle |
pushShuttle(Project project) |
static void |
registerAbstractRelationalRules(RelOptPlanner planner) |
static void |
registerAbstractRels(RelOptPlanner planner)
Deprecated.
|
static void |
registerAbstractRules(RelOptPlanner planner) |
private static void |
registerBaseRules(RelOptPlanner planner) |
private static void |
registerCalcRules(RelOptPlanner planner) |
static void |
registerDefaultRules(RelOptPlanner planner,
boolean enableMaterialziations,
boolean enableBindable) |
private static void |
registerEnumerableRules(RelOptPlanner planner) |
private static void |
registerMaterializationRules(RelOptPlanner planner) |
private static void |
registerReductionRules(RelOptPlanner planner) |
static RelNode |
renameIfNecessary(RelNode rel,
RelDataType desiredRowType)
Deprecated.
|
static RelNode |
replace(RelNode query,
RelNode find,
RelNode replace)
Within a relational expression
query , replaces occurrences of
find with replace . |
static RelNode |
replaceInput(RelNode parent,
int ordinal,
RelNode newInput)
Returns a shallow copy of a relational expression with a particular
input replaced.
|
private static RelNode |
replaceRecurse(RelNode query,
RelNode find,
RelNode replace)
|
private static boolean |
returnsJustFirstInput(RelNode joinRel) |
private static RexNode |
shiftFilter(int start,
int end,
int offset,
RexBuilder rexBuilder,
java.util.List<RelDataTypeField> joinFields,
int nTotalFields,
java.util.List<RelDataTypeField> rightFields,
RexNode filter) |
static JoinRelType |
simplifyJoin(RelNode joinRel,
com.google.common.collect.ImmutableList<RexNode> aboveFilters,
JoinRelType joinType)
Simplifies outer joins if filter above would reject nulls.
|
static RexNode |
splitCorrelatedFilterCondition(LogicalFilter filter,
java.util.List<RexInputRef> joinKeys,
java.util.List<RexNode> correlatedJoinKeys)
Deprecated.
|
static RexNode |
splitCorrelatedFilterCondition(LogicalFilter filter,
java.util.List<RexNode> joinKeys,
java.util.List<RexNode> correlatedJoinKeys,
boolean extractCorrelatedFieldAccess) |
private static void |
splitCorrelatedFilterCondition(LogicalFilter filter,
RexNode condition,
java.util.List<RexInputRef> joinKeys,
java.util.List<RexNode> correlatedJoinKeys,
java.util.List<RexNode> nonEquiList) |
private static void |
splitCorrelatedFilterCondition(LogicalFilter filter,
RexNode condition,
java.util.List<RexNode> joinKeys,
java.util.List<RexNode> correlatedJoinKeys,
java.util.List<RexNode> nonEquiList,
boolean extractCorrelatedFieldAccess) |
static void |
splitFilters(ImmutableBitSet childBitmap,
RexNode predicate,
java.util.List<RexNode> pushable,
java.util.List<RexNode> notPushable)
Splits a filter into two lists, depending on whether or not the filter
only references its child input
|
static RexNode |
splitJoinCondition(java.util.List<RelDataTypeField> sysFieldList,
java.util.List<RelNode> inputs,
RexNode condition,
java.util.List<java.util.List<RexNode>> joinKeys,
java.util.List<java.lang.Integer> filterNulls,
java.util.List<SqlOperator> rangeOp)
Splits out the equi-join (and optionally, a single non-equi) components
of a join condition, and returns what's left.
|
private static void |
splitJoinCondition(java.util.List<RelDataTypeField> sysFieldList,
java.util.List<RelNode> inputs,
RexNode condition,
java.util.List<java.util.List<RexNode>> joinKeys,
java.util.List<java.lang.Integer> filterNulls,
java.util.List<SqlOperator> rangeOp,
java.util.List<RexNode> nonEquiList) |
static RexNode |
splitJoinCondition(java.util.List<RelDataTypeField> sysFieldList,
RelNode leftRel,
RelNode rightRel,
RexNode condition,
java.util.List<RexNode> leftJoinKeys,
java.util.List<RexNode> rightJoinKeys,
java.util.List<java.lang.Integer> filterNulls,
java.util.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 RexNode |
splitJoinCondition(RelNode left,
RelNode right,
RexNode condition,
java.util.List<java.lang.Integer> leftKeys,
java.util.List<java.lang.Integer> rightKeys,
java.util.List<java.lang.Boolean> filterNulls)
Splits out the equi-join components of a join condition, and returns
what's left.
|
private static void |
splitJoinCondition(RexBuilder rexBuilder,
int leftFieldCount,
RexNode condition,
java.util.List<java.lang.Integer> leftKeys,
java.util.List<java.lang.Integer> rightKeys,
java.util.List<java.lang.Boolean> filterNulls,
java.util.List<RexNode> nonEquiList) |
static java.lang.String |
toString(RelNode rel)
Converts a relational expression to a string, showing just basic
attributes.
|
static java.lang.String |
toString(RelNode rel,
SqlExplainLevel detailLevel)
Converts a relational expression to a string.
|
static void |
validateValueAgainstConstraint(SqlNode sourceValue,
RexNode targetConstraint,
java.util.function.Supplier<CalciteContextException> errorSupplier)
Ensures that a source value does not violate the constraint of the target
column.
|
static void |
verifyTypeEquivalence(RelNode originalRel,
RelNode newRel,
java.lang.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.
|
static final boolean B
public static final double EPSILON
@Deprecated public static final com.google.common.base.Predicate<Filter> FILTER_PREDICATE
@Deprecated public static final com.google.common.base.Predicate<Project> PROJECT_PREDICATE
@Deprecated public static final com.google.common.base.Predicate<Calc> CALC_PREDICATE
public static boolean isPureLimit(RelNode rel)
public static boolean isPureOrder(RelNode rel)
public static boolean isLimit(RelNode rel)
public static boolean isOrder(RelNode rel)
public static java.util.Set<RelOptTable> findTables(RelNode rel)
public static java.util.List<RelOptTable> findAllTables(RelNode rel)
public static java.util.List<java.lang.String> findAllTableQualifiedNames(RelNode rel)
public static java.util.Set<CorrelationId> getVariablesSet(RelNode rel)
@Deprecated public static java.util.List<CorrelationId> getVariablesSetAndUsed(RelNode rel0, RelNode rel1)
public static java.util.Set<CorrelationId> getVariablesUsed(RelNode rel)
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
.
public static ImmutableBitSet correlationColumns(CorrelationId id, RelNode rel)
public static boolean notContainsCorrelation(RelNode r, CorrelationId correlationId, Litmus litmus)
Litmus.succeed()
if a given relational
expression does not contain a given correlation.public static void go(RelVisitor visitor, RelNode p)
RelVisitor
going on a given relational expression, and
returns the result.public static java.util.List<RelDataType> getFieldTypeList(RelDataType type)
type
- Struct typeRelDataType.getFieldNames()
public static boolean areRowTypesEqual(RelDataType rowType1, RelDataType rowType2, boolean compareNames)
public static void verifyTypeEquivalence(RelNode originalRel, RelNode newRel, java.lang.Object equivalenceClass)
originalRel
- canonical rel for equivalence classnewRel
- rel being added to equivalence classequivalenceClass
- object representing equivalence classpublic static Mappings.TargetMapping permutationIgnoreCast(java.util.List<RexNode> nodes, RelDataType inputRowType)
map.getTargetOpt(i)
is n
if
field i
projects input field n
or applies a cast on
n
, -1 if it is another expression.public static Mappings.TargetMapping permutation(java.util.List<RexNode> nodes, RelDataType inputRowType)
map.getTargetOpt(i)
is n
if
field i
projects input field n
, -1 if it is an
expression.@Deprecated public static RelNode createExistsPlan(RelOptCluster cluster, RelNode seekRel, java.util.List<RexNode> conditions, RexLiteral extraExpr, java.lang.String extraName)
@Deprecated public static RelOptUtil.Exists createExistsPlan(RelNode seekRel, RelOptUtil.SubQueryType subQueryType, RelOptUtil.Logic logic, boolean notIn)
public static RelOptUtil.Exists createExistsPlan(RelNode seekRel, RelOptUtil.SubQueryType subQueryType, RelOptUtil.Logic logic, boolean notIn, RelBuilder relBuilder)
EXISTS
or IN
statements.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 expressionsSqlToRelConverter.convertExists(org.apache.calcite.sql.SqlNode, org.apache.calcite.plan.RelOptUtil.SubQueryType, org.apache.calcite.plan.RelOptUtil.Logic, boolean, org.apache.calcite.rel.type.RelDataType)
@Deprecated public static RelNode createRenameRel(RelDataType outputType, RelNode rel)
@Deprecated public static RelNode createFilter(RelNode child, RexNode condition)
@Deprecated public static RelNode createFilter(RelNode child, RexNode condition, RelFactories.FilterFactory filterFactory)
public static RelNode createFilter(RelNode child, java.lang.Iterable<? extends RexNode> conditions)
public static RelNode createFilter(RelNode child, java.lang.Iterable<? extends RexNode> conditions, RelFactories.FilterFactory filterFactory)
@Deprecated public static RelNode createNullFilter(RelNode rel, java.lang.Integer[] fieldOrdinals)
public static RelNode createCastRel(RelNode rel, RelDataType castRowType, boolean rename)
rel
- producer of rows to be convertedcastRowType
- row type after castrename
- if true, use field names from castRowType; if false,
preserve field names from relpublic static RelNode createCastRel(RelNode rel, RelDataType castRowType, boolean rename, RelFactories.ProjectFactory projectFactory)
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 Factorypublic static java.util.Set<java.lang.Integer> getAllFields(Aggregate aggregate)
public static RelNode createSingleValueAggRel(RelOptCluster cluster, RelNode rel)
rel
- underlying rel@Deprecated public static RelNode createDistinctRel(RelNode rel)
RelBuilder.distinct()
.@Deprecated public static boolean analyzeSimpleEquiJoin(LogicalJoin join, int[] joinFieldOrdinals)
@Nonnull public static RexNode splitJoinCondition(RelNode left, RelNode right, RexNode condition, java.util.List<java.lang.Integer> leftKeys, java.util.List<java.lang.Integer> rightKeys, java.util.List<java.lang.Boolean> filterNulls)
L.A = R.X AND L.B = L.C AND (L.D = 5 OR L.E =
R.Y)
returns
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).
If filterNulls
is null, only join conditions
with EQUALS operators are considered equi-join components.
Rest (including IS NOT DISTINCT FROM) are returned in
remaining join condition.RexLiteral
true, but never null@Deprecated public static boolean isEqui(RelNode left, RelNode right, RexNode condition)
public static RexNode splitJoinCondition(java.util.List<RelDataTypeField> sysFieldList, RelNode leftRel, RelNode rightRel, RexNode condition, java.util.List<RexNode> leftJoinKeys, java.util.List<RexNode> rightJoinKeys, java.util.List<java.lang.Integer> filterNulls, java.util.List<SqlOperator> rangeOp)
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@Nonnull public static RexNode splitJoinCondition(java.util.List<RelDataTypeField> sysFieldList, java.util.List<RelNode> inputs, RexNode condition, java.util.List<java.util.List<RexNode>> joinKeys, java.util.List<java.lang.Integer> filterNulls, java.util.List<SqlOperator> rangeOp)
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@Deprecated public static RexNode splitCorrelatedFilterCondition(LogicalFilter filter, java.util.List<RexInputRef> joinKeys, java.util.List<RexNode> correlatedJoinKeys)
public static RexNode splitCorrelatedFilterCondition(LogicalFilter filter, java.util.List<RexNode> joinKeys, java.util.List<RexNode> correlatedJoinKeys, boolean extractCorrelatedFieldAccess)
private static void splitJoinCondition(java.util.List<RelDataTypeField> sysFieldList, java.util.List<RelNode> inputs, RexNode condition, java.util.List<java.util.List<RexNode>> joinKeys, java.util.List<java.lang.Integer> filterNulls, java.util.List<SqlOperator> rangeOp, java.util.List<RexNode> nonEquiList)
@Nonnull public static RexNode createEquiJoinCondition(RelNode left, java.util.List<java.lang.Integer> leftKeys, RelNode right, java.util.List<java.lang.Integer> rightKeys, RexBuilder rexBuilder)
public static SqlOperator op(SqlKind kind, SqlOperator operator)
private static void addJoinKey(java.util.List<RexNode> joinKeyList, RexNode key, boolean preserveLastElementInList)
private static void splitCorrelatedFilterCondition(LogicalFilter filter, RexNode condition, java.util.List<RexInputRef> joinKeys, java.util.List<RexNode> correlatedJoinKeys, java.util.List<RexNode> nonEquiList)
private static void splitCorrelatedFilterCondition(LogicalFilter filter, RexNode condition, java.util.List<RexNode> joinKeys, java.util.List<RexNode> correlatedJoinKeys, java.util.List<RexNode> nonEquiList, boolean extractCorrelatedFieldAccess)
private static void splitJoinCondition(RexBuilder rexBuilder, int leftFieldCount, RexNode condition, java.util.List<java.lang.Integer> leftKeys, java.util.List<java.lang.Integer> rightKeys, java.util.List<java.lang.Boolean> filterNulls, java.util.List<RexNode> nonEquiList)
public static RexCall collapseExpandedIsNotDistinctFromExpr(RexCall call, RexBuilder rexBuilder)
IS NOT DISTINCT FROM
expression.
Helper method for
splitJoinCondition(RexBuilder, int, RexNode, List, List, List, List)
and
splitJoinCondition(List, List, RexNode, List, List, List, List)
.
If the given expr call
is an expanded version of
IS NOT DISTINCT FROM
function call, collapses it and return a
IS NOT DISTINCT FROM
function call.
For example: t1.key IS NOT DISTINCT FROM t2.key
can rewritten in expanded form as
t1.key = t2.key OR (t1.key IS NULL AND t2.key IS NULL)
.
call
- Function expression to try collapsingrexBuilder
- RexBuilder
instance to create new RexCall
instances.private static RexCall doCollapseExpandedIsNotDistinctFromOrExpr(RexCall call, RexBuilder rexBuilder)
private static RexCall doCollapseExpandedIsNotDistinctFromCaseExpr(RexCall call, RexBuilder rexBuilder)
private static RexCall doCollapseExpandedIsNotDistinctFrom(RexBuilder rexBuilder, RexCall call, RexCall ifNull0Call, RexCall ifNull1Call, RexCall equalsCall)
@Deprecated public static void projectJoinInputs(RelNode[] inputRels, java.util.List<RexNode> leftJoinKeys, java.util.List<RexNode> rightJoinKeys, int systemColCount, java.util.List<java.lang.Integer> leftKeys, java.util.List<java.lang.Integer> rightKeys, java.util.List<java.lang.Integer> outputProj)
@Deprecated public static RelNode createProjectJoinRel(java.util.List<java.lang.Integer> outputProj, RelNode joinRel)
@Deprecated public static void registerAbstractRels(RelOptPlanner planner)
public static void registerAbstractRules(RelOptPlanner planner)
public static void registerAbstractRelationalRules(RelOptPlanner planner)
private static void registerEnumerableRules(RelOptPlanner planner)
private static void registerBaseRules(RelOptPlanner planner)
private static void registerReductionRules(RelOptPlanner planner)
private static void registerMaterializationRules(RelOptPlanner planner)
private static void registerCalcRules(RelOptPlanner planner)
public static void registerDefaultRules(RelOptPlanner planner, boolean enableMaterialziations, boolean enableBindable)
public static java.lang.String dumpPlan(java.lang.String header, RelNode rel, SqlExplainFormat format, SqlExplainLevel detailLevel)
header
- Header to print before the plan. Ignored if the format
is XMLrel
- Relational expression to explainformat
- Output formatdetailLevel
- Detail level@Deprecated public static java.lang.String dumpPlan(java.lang.String header, RelNode rel, boolean asXml, SqlExplainLevel detailLevel)
public static RelDataType createDmlRowType(SqlKind kind, RelDataTypeFactory typeFactory)
kind
- Kind of nodetypeFactory
- factory to use for creating type descriptorpublic static boolean eq(java.lang.String desc1, RelDataType type1, java.lang.String desc2, RelDataType type2, Litmus litmus)
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)public static boolean equal(java.lang.String desc1, RelDataType type1, java.lang.String desc2, RelDataType type2, Litmus litmus)
areRowTypesEqual(RelDataType, RelDataType, boolean)
. Both types
must not be null.desc1
- Description of role of first typetype1
- First typedesc2
- Description of role of second typetype2
- Second typelitmus
- Whether to assert if they are not equalpublic static boolean equalType(java.lang.String desc0, RelNode rel0, java.lang.String desc1, RelNode rel1, Litmus litmus)
public static RexNode isDistinctFrom(RexBuilder rexBuilder, RexNode x, RexNode y, boolean neg)
IS DISTINCT FROM
(or IS
NOT DISTINCT FROM
) sql operator.neg
- if false, returns a translation of IS NOT DISTINCT FROMprivate static RexNode isDistinctFromInternal(RexBuilder rexBuilder, RexNode x, RexNode y, boolean neg)
public static java.lang.String toString(RelNode rel)
public static java.lang.String toString(RelNode rel, SqlExplainLevel detailLevel)
@Deprecated public static RelNode renameIfNecessary(RelNode rel, RelDataType desiredRowType)
public static java.lang.String dumpType(RelDataType type)
public static java.util.List<RelDataTypeField> deduplicateColumns(java.util.List<RelDataTypeField> baseColumns, java.util.List<RelDataTypeField> extendedColumns)
public static void decomposeConjunction(RexNode rexPredicate, java.util.List<RexNode> rexList)
rexPredicate
- predicate to be analyzedrexList
- list of decomposed RexNodespublic static void decomposeConjunction(RexNode rexPredicate, java.util.List<RexNode> rexList, java.util.List<RexNode> notList)
For example, a AND NOT b AND NOT (c and d) AND TRUE AND NOT
FALSE
returns rexList = [a], notList = [b, c AND d]
.
TRUE and NOT FALSE expressions are ignored. FALSE and NOT TRUE
expressions are placed on rexList
and notList
as other
expressions.
For example, a AND TRUE AND NOT TRUE
returns
rexList = [a], notList = [TRUE]
.
rexPredicate
- predicate to be analyzedrexList
- list of decomposed RexNodes (except those with NOT)notList
- list of decomposed RexNodes that were prefixed NOTpublic static void decomposeDisjunction(RexNode rexPredicate, java.util.List<RexNode> rexList)
rexPredicate
- predicate to be analyzedrexList
- list of decomposed RexNodespublic static java.util.List<RexNode> conjunctions(RexNode rexPredicate)
For example, conjunctions(TRUE)
returns the empty list;
conjunctions(FALSE)
returns list {FALSE}
.
public static java.util.List<RexNode> disjunctions(RexNode rexPredicate)
For example, disjunctions(FALSE)
returns the empty list.
public static RexNode andJoinFilters(RexBuilder rexBuilder, RexNode left, RexNode right)
rexBuilder
- rexBuilder to create AND expressionleft
- filter on the left that the right will be AND'd toright
- filter on the rightRexUtil.composeConjunction(org.apache.calcite.rex.RexBuilder, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>)
public static void inferViewPredicates(java.util.Map<java.lang.Integer,RexNode> projectMap, java.util.List<RexNode> filters, RexNode constraint)
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.
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 analyzedpublic static java.util.Map<java.lang.Integer,RexNode> getColumnConstraints(ModifiableView modifiableViewTable, RelDataType targetRowType, RelDataTypeFactory typeFactory)
modifiableViewTable
- The modifiable view which has a constrainttargetRowType
- The target typepublic static void validateValueAgainstConstraint(SqlNode sourceValue, RexNode targetConstraint, java.util.function.Supplier<CalciteContextException> errorSupplier)
sourceValue
- The insert value being validatedtargetConstraint
- The constraint applied to sourceValue for validationerrorSupplier
- The function to apply when validation failspublic static java.util.List<java.lang.Integer> adjustKeys(java.util.List<java.lang.Integer> keys, int adjustment)
keys
- list of key valuesadjustment
- the amount to adjust the key values bypublic static JoinRelType simplifyJoin(RelNode joinRel, com.google.common.collect.ImmutableList<RexNode> aboveFilters, JoinRelType joinType)
joinRel
- JoinaboveFilters
- Filters from abovejoinType
- Join type, can not be inner joinpublic static boolean classifyFilters(RelNode joinRel, java.util.List<RexNode> filters, JoinRelType joinType, boolean pushInto, boolean pushLeft, boolean pushRight, java.util.List<RexNode> joinFilters, java.util.List<RexNode> leftFilters, java.util.List<RexNode> rightFilters)
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 childprivate static boolean returnsJustFirstInput(RelNode joinRel)
private static RexNode shiftFilter(int start, int end, int offset, RexBuilder rexBuilder, java.util.List<RelDataTypeField> joinFields, int nTotalFields, java.util.List<RelDataTypeField> rightFields, RexNode filter)
public static void splitFilters(ImmutableBitSet childBitmap, RexNode predicate, java.util.List<RexNode> pushable, java.util.List<RexNode> notPushable)
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@Deprecated public static boolean checkProjAndChildInputs(Project project, boolean checkNames)
public static java.util.List<RexNode> createSwappedJoinExprs(RelNode newJoin, Join origJoin, boolean origOrder)
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@Deprecated public static RexNode pushFilterPastProject(RexNode filter, Project projRel)
public static RexNode pushPastProject(RexNode node, Project project)
Project
to an equivalent expression on the Project's
input fields.node
- The expression to be convertedproject
- Project underneath the expressionpublic static java.util.List<RexNode> pushPastProject(java.util.List<? extends RexNode> nodes, Project project)
Project
to equivalent expressions on the Project's
input fields.nodes
- The expressions to be convertedproject
- Project underneath the expressionprivate static RexShuttle pushShuttle(Project project)
public static MultiJoin projectMultiJoin(MultiJoin multiJoin, Project project)
MultiJoin
to reflect
projection references from a
Project
that is on top of the
MultiJoin
.multiJoin
- the original MultiJoinproject
- the Project on top of the MultiJoinpublic static RelNode replaceInput(RelNode parent, int ordinal, RelNode newInput)
public static RelNode createProject(RelNode child, Mappings.TargetMapping mapping)
LogicalProject
that
projects particular fields of its input, according to a mapping.public static RelNode createProject(RelNode child, Mappings.TargetMapping mapping, RelFactories.ProjectFactory projectFactory)
public static boolean contains(RelNode ancestor, RelNode target)
target
occurs within a
relational expression ancestor
.public static RelNode replace(RelNode query, RelNode find, RelNode replace)
query
, replaces occurrences of
find
with replace
.@Deprecated public static RelOptTable.ToRelContext getContext(RelOptCluster cluster)
public static int countJoins(RelNode rootRel)
Join
nodes in a
tree.public static RelDataType permute(RelDataTypeFactory typeFactory, RelDataType rowType, Mapping mapping)
@Deprecated public static RelNode createProject(RelNode child, java.util.List<? extends RexNode> exprList, java.util.List<java.lang.String> fieldNameList)
@Deprecated public static RelNode createProject(RelNode child, java.util.List<Pair<RexNode,java.lang.String>> projectList, boolean optimize)
public static RelNode createProject(RelNode child, java.util.List<java.lang.Integer> posList)
Optimizes if the fields are the identity projection.
child
- Input relational expressionposList
- Source of each projected field@Deprecated public static RelNode createProject(RelNode child, java.util.List<? extends RexNode> exprs, java.util.List<java.lang.String> fieldNames, boolean optimize)
@Deprecated public static RelNode createProject(RelNode child, java.util.List<? extends RexNode> exprs, java.util.List<java.lang.String> fieldNames, boolean optimize, RelBuilder relBuilder)
RelBuilder.projectNamed(Iterable, Iterable, boolean)
@Deprecated public static RelNode createRename(RelNode rel, java.util.List<java.lang.String> fieldNames)
public static RelNode permute(RelNode rel, Permutation permutation, java.util.List<java.lang.String> fieldNames)
Optimizations:
LogicalCalc
or
LogicalProject
that is already
acting as a permutation, combines the new permutation with the old;If a permutation is combined with its inverse, these optimizations would combine to remove them both.
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 usedpublic static RelNode createProject(RelFactories.ProjectFactory factory, RelNode child, java.util.List<java.lang.Integer> posList)
Optimizes if the fields are the identity projection.
factory
- ProjectFactorychild
- Input relational expressionposList
- Source of each projected field@Deprecated public static RelNode projectMapping(RelNode rel, Mapping mapping, java.util.List<java.lang.String> fieldNames, RelFactories.ProjectFactory projectFactory)
public static boolean containsMultisetOrWindowedAgg(Calc calc)
Calc
contains multisets or windowed
aggregates.public static boolean containsMultisetOrWindowedAgg(Filter filter)
Filter
contains multisets or windowed
aggregates.public static boolean containsMultisetOrWindowedAgg(Project project)
Project
contains multisets or windowed
aggregates.public static RelNode pushDownJoinConditions(Join originalJoin, RelBuilder relBuilder)
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.
originalJoin
- Join whose condition is to be pushed downrelBuilder
- Factory to create project operator@Deprecated public static RelNode pushDownJoinConditions(Join originalJoin)
@Deprecated public static RelNode pushDownJoinConditions(Join originalJoin, RelFactories.ProjectFactory projectFactory)
private static RelNode pushDownJoinConditions(Join originalJoin, RelBuilderFactory relBuilderFactory)
private static boolean containsGet(RexNode node)
private static RexNode pushDownEqualJoinConditions(RexNode condition, int leftCount, int rightCount, java.util.List<RexNode> extraLeftExprs, java.util.List<RexNode> extraRightExprs, RexBuilder builder)
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.
private static void fix(java.util.List<RexNode> operands, int before, int after)
private static boolean containsNullableFields(RelNode r)
The method is cautious: It may sometimes return true
when the
actual answer is false
. In particular, it does this when there
is no executor, or the executor is not a sub-class of
RexExecutorImpl
.
public static boolean forceEquiJoin(Join join)
Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.