Class RelOptUtil


  • public abstract class RelOptUtil
    extends java.lang.Object
    RelOptUtil defines static utility methods for use in optimizing RelNodes.
    • Field Detail

      • FILTER_PREDICATE

        @Deprecated
        public static final com.google.common.base.Predicate<Filter> FILTER_PREDICATE
        Deprecated.
      • PROJECT_PREDICATE

        @Deprecated
        public static final com.google.common.base.Predicate<Project> PROJECT_PREDICATE
        Deprecated.
      • CALC_PREDICATE

        @Deprecated
        public static final com.google.common.base.Predicate<Calc> CALC_PREDICATE
        Deprecated.
    • Constructor Detail

      • RelOptUtil

        public RelOptUtil()
    • Method Detail

      • isPureLimit

        public static boolean isPureLimit​(RelNode rel)
        Whether this node is a limit without sort specification.
      • isPureOrder

        public static boolean isPureOrder​(RelNode rel)
        Whether this node is a sort without limit specification.
      • isLimit

        public static boolean isLimit​(RelNode rel)
        Whether this node contains a limit specification.
      • isOrder

        public static boolean isOrder​(RelNode rel)
        Whether this node contains a sort specification.
      • findTables

        public static java.util.Set<RelOptTable> findTables​(RelNode rel)
        Returns a set of tables used by this expression or its children
      • findAllTables

        public static java.util.List<RelOptTable> findAllTables​(RelNode rel)
        Returns a list of all tables used by this expression or its children
      • findAllTableQualifiedNames

        public 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.
      • getVariablesSet

        public static java.util.Set<CorrelationId> getVariablesSet​(RelNode rel)
        Returns a list of variables set by a relational expression or its descendants.
      • getVariablesSetAndUsed

        @Deprecated
        public static java.util.List<CorrelationId> getVariablesSetAndUsed​(RelNode rel0,
                                                                           RelNode rel1)
        Deprecated.
      • getVariablesUsed

        public static java.util.Set<CorrelationId> getVariablesUsed​(RelNode rel)
        Returns a 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.

      • correlationColumns

        public static ImmutableBitSet correlationColumns​(CorrelationId id,
                                                         RelNode rel)
        Finds which columns of a correlation variable are used within a relational expression.
      • notContainsCorrelation

        public 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.
      • go

        public static void go​(RelVisitor visitor,
                              RelNode p)
        Sets a RelVisitor going on a given relational expression, and returns the result.
      • getFieldTypeList

        public static java.util.List<RelDataType> getFieldTypeList​(RelDataType type)
        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:
        RelDataType.getFieldNames()
      • areRowTypesEqual

        public static boolean areRowTypesEqual​(RelDataType rowType1,
                                               RelDataType rowType2,
                                               boolean compareNames)
      • verifyTypeEquivalence

        public 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.
        Parameters:
        originalRel - canonical rel for equivalence class
        newRel - rel being added to equivalence class
        equivalenceClass - object representing equivalence class
      • permutationIgnoreCast

        public static Mappings.TargetMapping permutationIgnoreCast​(java.util.List<RexNode> nodes,
                                                                   RelDataType inputRowType)
        Returns a permutation describing where output fields come from. In the returned map, value of map.getTargetOpt(i) is n if field i projects input field n or applies a cast on n, -1 if it is another expression.
      • permutation

        public static Mappings.TargetMapping permutation​(java.util.List<RexNode> nodes,
                                                         RelDataType inputRowType)
        Returns a permutation describing where output fields come from. In the returned map, value of map.getTargetOpt(i) is n if field i projects input field n, -1 if it is an expression.
      • createFilter

        @Deprecated
        public static RelNode createFilter​(RelNode child,
                                           RexNode condition)
        Deprecated.
      • createFilter

        public 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.
      • createFilter

        public 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.
      • createNullFilter

        @Deprecated
        public static RelNode createNullFilter​(RelNode rel,
                                               java.lang.Integer[] fieldOrdinals)
        Deprecated.
      • createCastRel

        public static RelNode createCastRel​(RelNode rel,
                                            RelDataType castRowType,
                                            boolean rename)
        Creates a projection which casts a rel's output to a desired row type.
        Parameters:
        rel - producer of rows to be converted
        castRowType - row type after cast
        rename - 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.
        Parameters:
        rel - producer of rows to be converted
        castRowType - row type after cast
        rename - if true, use field names from castRowType; if false, preserve field names from rel
        projectFactory - Project Factory
        Returns:
        conversion rel
      • getAllFields

        public static java.util.Set<java.lang.Integer> getAllFields​(Aggregate aggregate)
        Gets all fields in an aggregate.
      • createSingleValueAggRel

        public static RelNode createSingleValueAggRel​(RelOptCluster cluster,
                                                      RelNode rel)
        Creates a LogicalAggregate that removes all duplicates from the result of an underlying relational expression.
        Parameters:
        rel - underlying rel
        Returns:
        rel implementing SingleValueAgg
      • analyzeSimpleEquiJoin

        @Deprecated
        public static boolean analyzeSimpleEquiJoin​(LogicalJoin join,
                                                    int[] joinFieldOrdinals)
        Deprecated.
      • splitJoinCondition

        @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)
        Splits out the equi-join components of a join condition, and returns what's left. For example, given the condition
        L.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 join
        right - right input to join
        condition - join condition
        leftKeys - The ordinals of the fields from the left input which are equi-join keys
        rightKeys - The ordinals of the fields from the right input which are equi-join keys
        filterNulls - 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.
        Returns:
        remaining join filters that are not equijoins; may return a RexLiteral true, but never null
      • isEqui

        @Deprecated
        public static boolean isEqui​(RelNode left,
                                     RelNode right,
                                     RexNode condition)
        Deprecated.
      • splitJoinCondition

        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)
        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 fields
        leftRel - left join input
        rightRel - right join input
        condition - join condition
        leftJoinKeys - The join keys from the left input which are equi-join keys
        rightJoinKeys - The join keys from the right input which are equi-join keys
        filterNulls - 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

        @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)
        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 fields
        inputs - join inputs
        condition - join condition
        joinKeys - The join keys from the inputs which are equi-join keys
        filterNulls - 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
      • splitCorrelatedFilterCondition

        @Deprecated
        public static RexNode splitCorrelatedFilterCondition​(LogicalFilter filter,
                                                             java.util.List<RexInputRef> joinKeys,
                                                             java.util.List<RexNode> correlatedJoinKeys)
        Deprecated.
      • splitCorrelatedFilterCondition

        public static RexNode splitCorrelatedFilterCondition​(LogicalFilter filter,
                                                             java.util.List<RexNode> joinKeys,
                                                             java.util.List<RexNode> correlatedJoinKeys,
                                                             boolean extractCorrelatedFieldAccess)
      • splitJoinCondition

        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)
      • createEquiJoinCondition

        @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)
        Builds an equi-join condition from a set of left and right keys.
      • addJoinKey

        private static void addJoinKey​(java.util.List<RexNode> joinKeyList,
                                       RexNode key,
                                       boolean preserveLastElementInList)
      • splitCorrelatedFilterCondition

        private static void splitCorrelatedFilterCondition​(LogicalFilter filter,
                                                           RexNode condition,
                                                           java.util.List<RexInputRef> joinKeys,
                                                           java.util.List<RexNode> correlatedJoinKeys,
                                                           java.util.List<RexNode> nonEquiList)
      • splitCorrelatedFilterCondition

        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)
      • splitJoinCondition

        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)
      • collapseExpandedIsNotDistinctFromExpr

        public static RexCall collapseExpandedIsNotDistinctFromExpr​(RexCall call,
                                                                    RexBuilder rexBuilder)
        Collapses an expanded version of 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).

        Parameters:
        call - Function expression to try collapsing
        rexBuilder - RexBuilder instance to create new RexCall instances.
        Returns:
        If the given function is an expanded IS NOT DISTINCT FROM function call, return a IS NOT DISTINCT FROM function call. Otherwise return the input function call as it is.
      • doCollapseExpandedIsNotDistinctFromOrExpr

        private static RexCall doCollapseExpandedIsNotDistinctFromOrExpr​(RexCall call,
                                                                         RexBuilder rexBuilder)
      • doCollapseExpandedIsNotDistinctFromCaseExpr

        private static RexCall doCollapseExpandedIsNotDistinctFromCaseExpr​(RexCall call,
                                                                           RexBuilder rexBuilder)
      • projectJoinInputs

        @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.
      • createProjectJoinRel

        @Deprecated
        public static RelNode createProjectJoinRel​(java.util.List<java.lang.Integer> outputProj,
                                                   RelNode joinRel)
        Deprecated.
      • registerAbstractRels

        @Deprecated
        public static void registerAbstractRels​(RelOptPlanner planner)
        Deprecated.
      • registerAbstractRules

        public static void registerAbstractRules​(RelOptPlanner planner)
      • registerAbstractRelationalRules

        public static void registerAbstractRelationalRules​(RelOptPlanner planner)
      • registerEnumerableRules

        private static void registerEnumerableRules​(RelOptPlanner planner)
      • registerBaseRules

        private static void registerBaseRules​(RelOptPlanner planner)
      • registerReductionRules

        private static void registerReductionRules​(RelOptPlanner planner)
      • registerMaterializationRules

        private static void registerMaterializationRules​(RelOptPlanner planner)
      • registerCalcRules

        private static void registerCalcRules​(RelOptPlanner planner)
      • registerDefaultRules

        public static void registerDefaultRules​(RelOptPlanner planner,
                                                boolean enableMaterialziations,
                                                boolean enableBindable)
      • dumpPlan

        public static java.lang.String dumpPlan​(java.lang.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 XML
        rel - Relational expression to explain
        format - Output format
        detailLevel - Detail level
        Returns:
        Plan
      • dumpPlan

        @Deprecated
        public static java.lang.String dumpPlan​(java.lang.String header,
                                                RelNode rel,
                                                boolean asXml,
                                                SqlExplainLevel detailLevel)
        Deprecated.
      • createDmlRowType

        public 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.
        Parameters:
        kind - Kind of node
        typeFactory - factory to use for creating type descriptor
        Returns:
        created type
      • eq

        public static boolean eq​(java.lang.String desc1,
                                 RelDataType type1,
                                 java.lang.String desc2,
                                 RelDataType type2,
                                 Litmus litmus)
        Returns whether two types are equal using '='.
        Parameters:
        desc1 - Description of first type
        type1 - First type
        desc2 - Description of second type
        type2 - Second type
        litmus - What to do if an error is detected (types are not equal)
        Returns:
        Whether the types are equal
      • equal

        public 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). Both types must not be null.
        Parameters:
        desc1 - Description of role of first type
        type1 - First type
        desc2 - Description of role of second type
        type2 - Second type
        litmus - Whether to assert if they are not equal
        Returns:
        Whether the types are equal
      • equalType

        public 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.
      • isDistinctFrom

        public 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.
        Parameters:
        neg - if false, returns a translation of IS NOT DISTINCT FROM
      • toString

        public static java.lang.String toString​(RelNode rel)
        Converts a relational expression to a string, showing just basic attributes.
      • toString

        public static java.lang.String toString​(RelNode rel,
                                                SqlExplainLevel detailLevel)
        Converts a relational expression to a string.
      • renameIfNecessary

        @Deprecated
        public static RelNode renameIfNecessary​(RelNode rel,
                                                RelDataType desiredRowType)
        Deprecated.
      • dumpType

        public static java.lang.String dumpType​(RelDataType type)
      • deduplicateColumns

        public 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.
      • decomposeConjunction

        public static void decomposeConjunction​(RexNode rexPredicate,
                                                java.util.List<RexNode> rexList)
        Decomposes a predicate into a list of expressions that are AND'ed together.
        Parameters:
        rexPredicate - predicate to be analyzed
        rexList - list of decomposed RexNodes
      • decomposeConjunction

        public 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.

        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].

        Parameters:
        rexPredicate - predicate to be analyzed
        rexList - list of decomposed RexNodes (except those with NOT)
        notList - list of decomposed RexNodes that were prefixed NOT
      • decomposeDisjunction

        public static void decomposeDisjunction​(RexNode rexPredicate,
                                                java.util.List<RexNode> rexList)
        Decomposes a predicate into a list of expressions that are OR'ed together.
        Parameters:
        rexPredicate - predicate to be analyzed
        rexList - list of decomposed RexNodes
      • conjunctions

        public static java.util.List<RexNode> conjunctions​(RexNode rexPredicate)
        Returns a condition decomposed by AND.

        For example, conjunctions(TRUE) returns the empty list; conjunctions(FALSE) returns list {FALSE}.

      • disjunctions

        public static java.util.List<RexNode> disjunctions​(RexNode rexPredicate)
        Returns a condition decomposed by OR.

        For example, disjunctions(FALSE) returns the empty list.

      • inferViewPredicates

        public 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.

        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 method
        filters - List of remaining filters, to be populated by this method
        constraint - Constraint to be analyzed
      • getColumnConstraints

        public 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.
        Parameters:
        modifiableViewTable - The modifiable view which has a constraint
        targetRowType - The target type
      • validateValueAgainstConstraint

        public 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.
        Parameters:
        sourceValue - The insert value being validated
        targetConstraint - The constraint applied to sourceValue for validation
        errorSupplier - The function to apply when validation fails
      • adjustKeys

        public 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.
        Parameters:
        keys - list of key values
        adjustment - 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 - Join
        aboveFilters - Filters from above
        joinType - Join type, can not be inner join
      • classifyFilters

        public 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. 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 node
        filters - filters to be classified
        joinType - join type
        pushInto - whether filters can be pushed into the ON clause
        pushLeft - true if filters can be pushed to the left
        pushRight - true if filters can be pushed to the right
        joinFilters - list of filters to push to the join
        leftFilters - list of filters to push to the left child
        rightFilters - list of filters to push to the right child
        Returns:
        whether at least one filter was pushed
      • returnsJustFirstInput

        private static boolean returnsJustFirstInput​(RelNode joinRel)
      • splitFilters

        public 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
        Parameters:
        childBitmap - Fields in the child
        predicate - filters that will be split
        pushable - returns the list of filters that can be pushed to the child input
        notPushable - returns the list of filters that cannot be pushed to the child input
      • checkProjAndChildInputs

        @Deprecated
        public static boolean checkProjAndChildInputs​(Project project,
                                                      boolean checkNames)
        Deprecated.
      • createSwappedJoinExprs

        public static java.util.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 swapped
        origJoin - original LogicalJoin
        origOrder - 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
        public static RexNode pushFilterPastProject​(RexNode filter,
                                                    Project projRel)
        Deprecated.
      • pushPastProject

        public 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.
        Parameters:
        node - The expression to be converted
        project - Project underneath the expression
        Returns:
        converted expression
      • pushPastProject

        public 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.
        Parameters:
        nodes - The expressions to be converted
        project - Project underneath the expression
        Returns:
        converted expressions
      • projectMultiJoin

        public static MultiJoin projectMultiJoin​(MultiJoin multiJoin,
                                                 Project project)
        Creates a new MultiJoin to reflect projection references from a Project that is on top of the MultiJoin.
        Parameters:
        multiJoin - the original MultiJoin
        project - the Project on top of the MultiJoin
        Returns:
        the new MultiJoin
      • addTrait

        public static <T extends RelNode> T addTrait​(T rel,
                                                     RelTrait trait)
      • replaceInput

        public static RelNode replaceInput​(RelNode parent,
                                           int ordinal,
                                           RelNode newInput)
        Returns a shallow copy of a relational expression with a particular input replaced.
      • contains

        public static boolean contains​(RelNode ancestor,
                                       RelNode target)
        Returns whether relational expression target occurs within a relational expression ancestor.
      • replace

        public static RelNode replace​(RelNode query,
                                      RelNode find,
                                      RelNode replace)
        Within a relational expression query, replaces occurrences of find with replace.
      • countJoins

        public static int countJoins​(RelNode rootRel)
        Returns the number of Join nodes in a tree.
      • createProject

        @Deprecated
        public static RelNode createProject​(RelNode child,
                                            java.util.List<? extends RexNode> exprList,
                                            java.util.List<java.lang.String> fieldNameList)
        Deprecated.
      • createProject

        @Deprecated
        public static RelNode createProject​(RelNode child,
                                            java.util.List<Pair<RexNode,​java.lang.String>> projectList,
                                            boolean optimize)
        Deprecated.
      • createProject

        public static RelNode createProject​(RelNode child,
                                            java.util.List<java.lang.Integer> posList)
        Creates a relational expression that projects the given fields of the input.

        Optimizes if the fields are the identity projection.

        Parameters:
        child - Input relational expression
        posList - Source of each projected field
        Returns:
        Relational expression that projects given fields
      • createProject

        @Deprecated
        public static RelNode createProject​(RelNode child,
                                            java.util.List<? extends RexNode> exprs,
                                            java.util.List<java.lang.String> fieldNames,
                                            boolean optimize)
        Deprecated.
      • createRename

        @Deprecated
        public static RelNode createRename​(RelNode rel,
                                           java.util.List<java.lang.String> fieldNames)
        Deprecated.
      • permute

        public 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.

        Optimizations:

        • If the relational expression is a LogicalCalc or LogicalProject that 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 expression
        permutation - Permutation to apply to fields
        fieldNames - 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
      • createProject

        public 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.

        Optimizes if the fields are the identity projection.

        Parameters:
        factory - ProjectFactory
        child - Input relational expression
        posList - Source of each projected field
        Returns:
        Relational expression that projects given fields
      • containsMultisetOrWindowedAgg

        public static boolean containsMultisetOrWindowedAgg​(Calc calc)
        Predicate for whether a Calc contains multisets or windowed aggregates.
      • containsMultisetOrWindowedAgg

        public static boolean containsMultisetOrWindowedAgg​(Filter filter)
        Predicate for whether a Filter contains multisets or windowed aggregates.
      • containsMultisetOrWindowedAgg

        public static boolean containsMultisetOrWindowedAgg​(Project project)
        Predicate for whether a Project contains multisets or windowed aggregates.
      • pushDownJoinConditions

        public static RelNode pushDownJoinConditions​(Join originalJoin,
                                                     RelBuilder relBuilder)
        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 down
        relBuilder - Factory to create project operator
      • pushDownJoinConditions

        @Deprecated
        public static RelNode pushDownJoinConditions​(Join originalJoin)
        Deprecated.
      • containsGet

        private static boolean containsGet​(RexNode node)
      • pushDownEqualJoinConditions

        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.

        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.

      • fix

        private static void fix​(java.util.List<RexNode> operands,
                                int before,
                                int after)
      • containsNullableFields

        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.

        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.

      • forceEquiJoin

        public 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.