Class RexUtil
- java.lang.Object
-
- org.apache.calcite.rex.RexUtil
-
public class RexUtil extends Object
Default implementation ofRexUtil
, the class was copied over because of current Calcite way of inferring constants from IS NOT DISTINCT FROM clashes with filter push down.Lines 397 ~ 399, Use Calcite 1.32.0 behavior for
gatherConstraints(Class, RexNode, Map, Set, RexBuilder)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RexUtil.ExprSimplifier
Deprecated.static class
RexUtil.FieldAccessFinder
Visitor which builds a bitmap of the inputs used by an expression.static class
RexUtil.FixNullabilityShuttle
Shuttle that fixes up an expression to match changes in nullability of input fields.static class
RexUtil.RexFinder
Visitor that tells whether a node matching a particular description exists in a tree.static class
RexUtil.SubQueryFinder
Visitor that throwsUtil.FoundOne
if applied to an expression that contains aRexSubQuery
.
-
Field Summary
Fields Modifier and Type Field Description static org.apache.calcite.rex.RexExecutor
EXECUTOR
Executor for a bit of constant reduction.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <E> boolean
all(List<? extends E> list, org.apache.calcite.linq4j.function.Predicate1<E> predicate)
Returns whetherpredicate
is true for all elements oflist
.static boolean
allLiterals(List<org.apache.calcite.rex.RexNode> expressionOperands)
Returns whether every expression in a list is a literal.static org.apache.calcite.rex.RexNode
andNot(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e, Iterable<? extends org.apache.calcite.rex.RexNode> notTerms)
Creates the expressione1 AND NOT notTerm1 AND NOT notTerm2 ...
.static org.apache.calcite.rex.RexNode
andNot(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e, org.apache.calcite.rex.RexNode... notTerms)
Creates the expressione1 AND NOT notTerm1 AND NOT notTerm2 ...
.static void
apply(org.apache.calcite.rex.RexVisitor<Void> visitor, List<? extends org.apache.calcite.rex.RexNode> exprs, @Nullable org.apache.calcite.rex.RexNode expr)
Applies a visitor to a list of expressions and, if specified, a single expression.static void
apply(org.apache.calcite.rex.RexVisitor<Void> visitor, org.apache.calcite.rex.RexNode[] exprs, @Nullable org.apache.calcite.rex.RexNode expr)
Applies a visitor to an array of expressions and, if specified, a single expression.static <T extends org.apache.calcite.rex.RexNode>
T[]apply(org.apache.calcite.rex.RexVisitor<T> shuttle, T[] exprs)
Applies a shuttle to an array of expressions.static List<org.apache.calcite.rex.RexNode>
apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Applies a mapping to an iterable over expressions.static List<org.apache.calcite.rel.RelCollation>
apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, List<org.apache.calcite.rel.RelCollation> collationList)
Applies a mapping to a collation list.static org.apache.calcite.rel.RelCollation
apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, org.apache.calcite.rel.RelCollation collation)
Applies a mapping to a collation.static @Nullable org.apache.calcite.rel.RelFieldCollation
apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, org.apache.calcite.rel.RelFieldCollation fieldCollation)
Applies a mapping to a field collation.static org.apache.calcite.rex.RexNode
apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, org.apache.calcite.rex.RexNode node)
Applies a mapping to an expression.static List<org.apache.calcite.rel.RelFieldCollation>
applyFields(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, List<org.apache.calcite.rel.RelFieldCollation> fieldCollations)
Applies a mapping to a list of field collations.static boolean
canReinterpretOverflow(org.apache.calcite.rex.RexCall call)
static boolean
compatibleTypes(List<org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.rel.type.RelDataType type, org.apache.calcite.util.Litmus litmus)
Returns whether the type of an array of expressions is compatible with a struct type.static org.apache.calcite.rex.RexNode
composeConjunction(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends @Nullable org.apache.calcite.rex.RexNode> nodes)
AscomposeConjunction(RexBuilder, Iterable, boolean)
but never returns null.static @Nullable org.apache.calcite.rex.RexNode
composeConjunction(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends @Nullable org.apache.calcite.rex.RexNode> nodes, boolean nullOnEmpty)
Converts a collection of expressions into an AND.static org.apache.calcite.rex.RexNode
composeDisjunction(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Converts a collection of expressions into an OR.static @Nullable org.apache.calcite.rex.RexNode
composeDisjunction(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends org.apache.calcite.rex.RexNode> nodes, boolean nullOnEmpty)
Converts a collection of expressions into an OR, optionally returning null if the list is empty.static boolean
containComplexExprs(List<org.apache.calcite.rex.RexNode> exprs)
Returns whether a list of expressions contains complex expressions, that is, a call whose arguments are notRexVariable
(or a subtype such asRexInputRef
) orRexLiteral
.static boolean
containIdentity(List<? extends org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.rel.type.RelDataType rowType, org.apache.calcite.util.Litmus litmus)
Returns whether the leading edge of a given array of expressions is whollyRexInputRef
objects with types corresponding to the underlying datatype.static boolean
containNoCommonExprs(List<org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.util.Litmus litmus)
Returns whether an array of expressions has any common sub-expressions.static boolean
containNoForwardRefs(List<org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.rel.type.RelDataType inputRowType, org.apache.calcite.util.Litmus litmus)
Returns whether an array of expressions contains no forward references.static boolean
containsCorrelation(org.apache.calcite.rex.RexNode condition)
Returns whether an expression contains aRexCorrelVariable
.static boolean
containsFieldAccess(org.apache.calcite.rex.RexNode node)
Returns whether a given tree contains anyRexFieldAccess
nodes.static boolean
containsInputRef(org.apache.calcite.rex.RexNode node)
Returns whether a given tree contains any {link RexInputRef} nodes.static boolean
containsTableInputRef(List<org.apache.calcite.rex.RexNode> nodes)
Returns whether any of the given expression trees contains a {link RexTableInputRef} node.static @Nullable org.apache.calcite.rex.RexTableInputRef
containsTableInputRef(org.apache.calcite.rex.RexNode node)
Returns whether a given tree contains any {link RexTableInputRef} nodes.static org.apache.calcite.rel.type.RelDataType
createStructType(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, List<? extends org.apache.calcite.rex.RexNode> exprs, @Nullable List<? extends @Nullable String> names, org.apache.calcite.sql.validate.SqlValidatorUtil.Suggester suggester)
Creates a record type with specified field names.static org.apache.calcite.rel.type.RelDataType
createStructType(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, List<? extends org.apache.calcite.rex.RexNode> exprs, List<String> names)
Deprecated.static org.apache.calcite.rel.type.RelDataType
createStructType(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, List<org.apache.calcite.rex.RexNode> exprs)
Creates a record type with anonymous field names.static boolean
eq(org.apache.calcite.rex.RexNode e1, org.apache.calcite.rex.RexNode e2)
Deprecated.static <E> boolean
exists(List<? extends E> list, org.apache.calcite.linq4j.function.Predicate1<E> predicate)
Returns whether there is an element inlist
for whichpredicate
is true.static org.apache.calcite.rex.RexNode
expandSearch(org.apache.calcite.rex.RexBuilder rexBuilder, @Nullable org.apache.calcite.rex.RexProgram program, org.apache.calcite.rex.RexNode node)
Expands all the calls toSqlStdOperatorTable.SEARCH
in an expression.static org.apache.calcite.rex.RexNode
expandSearch(org.apache.calcite.rex.RexBuilder rexBuilder, @Nullable org.apache.calcite.rex.RexProgram program, org.apache.calcite.rex.RexNode node, int maxComplexity)
Expands calls toSqlStdOperatorTable.SEARCH
whose complexity is greater thanmaxComplexity
in an expression.static List<org.apache.calcite.rel.type.RelDataTypeFamily>
families(List<org.apache.calcite.rel.type.RelDataType> types)
static RexUtil.RexFinder
find(Set<org.apache.calcite.sql.SqlKind> kinds)
Returns a visitor that finds nodes of givenSqlKind
s.static RexUtil.RexFinder
find(org.apache.calcite.rex.RexInputRef ref)
Returns a visitor that finds a particularRexInputRef
.static RexUtil.RexFinder
find(org.apache.calcite.sql.SqlKind kind)
Returns a visitor that finds nodes of a givenSqlKind
.static @Nullable org.apache.calcite.rex.RexCall
findOperatorCall(org.apache.calcite.sql.SqlOperator operator, org.apache.calcite.rex.RexNode node)
Returns whether a given node contains a RexCall with a specified operator.static List<org.apache.calcite.rex.RexNode>
fixUp(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> nodes, List<org.apache.calcite.rel.type.RelDataType> fieldTypes)
Fixes up the type of allRexInputRef
s in an expression to match differences in nullability.static List<org.apache.calcite.rex.RexNode>
fixUp(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> nodes, org.apache.calcite.rel.type.RelDataType rowType)
Deprecated.static List<org.apache.calcite.rex.RexNode>
flatten(List<? extends org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.sql.SqlOperator op)
Converts a list of operands into a list that is flat with respect to the given operator.static org.apache.calcite.rex.RexNode
flatten(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node)
Flattens an expression.static com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode>
flattenAnd(Iterable<? extends @Nullable org.apache.calcite.rex.RexNode> nodes)
Flattens a list of AND nodes.static com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode>
flattenOr(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Flattens a list of OR nodes.static Set<org.apache.calcite.rex.RexTableInputRef.RelTableRef>
gatherTableReferences(List<org.apache.calcite.rex.RexNode> nodes)
Gather all table references in input expressions.static List<org.apache.calcite.rex.RexNode>
generateCastExpressions(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rel.type.RelDataType lhsRowType, List<org.apache.calcite.rex.RexNode> rhsExps)
Generates a cast for a row type.static List<org.apache.calcite.rex.RexNode>
generateCastExpressions(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rel.type.RelDataType lhsRowType, org.apache.calcite.rel.type.RelDataType rhsRowType)
Generates a cast from one row type to another.static org.apache.calcite.util.ImmutableBitSet
getNonConstColumns(List<org.apache.calcite.rex.RexNode> expressions)
Given some expressions, gets the indices of the non-constant ones.static org.apache.calcite.util.ImmutableBitSet
getNonConstColumns(org.apache.calcite.util.ImmutableBitSet columns, List<org.apache.calcite.rex.RexNode> expressions)
Given some expressions and columns, gets the indices of the non-constant ones.static double
getSelectivity(@Nullable org.apache.calcite.rex.RexNode exp)
Returns a guess for the selectivity of an expression.static @Nullable org.apache.calcite.rex.RexNode
invert(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexCall call)
static boolean
isAtomic(org.apache.calcite.rex.RexNode expr)
static boolean
isCallTo(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.SqlOperator op)
Returns whether anode
is acall
to a givenoperator
.static boolean
isCasePredicate(org.apache.calcite.rex.RexCall call, int i)
Returns whether a given operand of a CASE expression is a predicate.static boolean
isConstant(org.apache.calcite.rex.RexNode node)
Returns whether node is made up of constants.static boolean
isDeterministic(org.apache.calcite.rex.RexNode e)
Returns whether a given expression is deterministic.static boolean
isFlat(org.apache.calcite.rex.RexNode expr)
Returns false if the expression can be optimized by flattening calls to an associative operator such as AND and OR.static boolean
isIdentity(List<? extends org.apache.calcite.rex.RexNode> exps, org.apache.calcite.rel.type.RelDataType inputRowType)
Returns whether a list of expressions projects the incoming fields.static boolean
isLiteral(org.apache.calcite.rex.RexNode node, boolean allowCast)
Returns whether a node represents a literal.static boolean
isLosslessCast(org.apache.calcite.rel.type.RelDataType source, org.apache.calcite.rel.type.RelDataType target)
Returns whether the conversion fromsource
totarget
type is a 'loss-less' cast, that is, a cast from which the original value of the field can be certainly recovered.static boolean
isLosslessCast(org.apache.calcite.rex.RexNode node)
Returns whether the input is a 'loss-less' cast, that is, a cast from which the original value of the field can be certainly recovered.static boolean
isNull(org.apache.calcite.rex.RexNode expr)
Returns whether a node represents the NULL value or a series of nestedCAST(NULL AS type)
calls.static boolean
isNullabilityCast(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.rex.RexNode node)
Returns whether an expression is a cast just for the purposes of nullability, not changing any other aspect of the type.static boolean
isNullLiteral(org.apache.calcite.rex.RexNode node, boolean allowCast)
Returns whether a node represents the NULL value.static boolean
isReferenceOrAccess(org.apache.calcite.rex.RexNode node, boolean allowCast)
Returns whether a node represents an input reference or field access.static boolean
isSymbolLiteral(org.apache.calcite.rex.RexNode expr)
Returns whether a node represents aSqlTypeName.SYMBOL
literal.static org.apache.calcite.util.Pair<org.apache.calcite.rex.RexNode,String>
makeKey(org.apache.calcite.rex.RexNode expr)
Creates a key forRexNode
which is the same as another key of another RexNode only if the two have both the same type and textual representation.static @Nullable org.apache.calcite.rex.RexNode
negate(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexCall call)
static int
nodeCount(List<? extends org.apache.calcite.rex.RexNode> nodes)
Returns the number of nodes (including leaves) in a list of expressions.static org.apache.calcite.rex.RexNode
not(org.apache.calcite.rex.RexNode e)
Negates a logical expression by adding or removing a NOT.static com.google.common.base.Function<org.apache.calcite.rex.RexNode,org.apache.calcite.rex.RexNode>
notFn(org.apache.calcite.rex.RexBuilder rexBuilder)
Deprecated.static org.apache.calcite.sql.SqlOperator
op(org.apache.calcite.sql.SqlKind kind)
static <C extends org.apache.calcite.rex.RexNode>
com.google.common.collect.ImmutableMap<org.apache.calcite.rex.RexNode,C>predicateConstants(Class<C> clazz, org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> predicates)
Creates a map containing each (e, constant) pair that occurs within a predicate list.static org.apache.calcite.rex.RexNode
pullFactors(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node)
Creates an equivalent version of a node where common factors among ORs are pulled up.static boolean
removeAll(List<org.apache.calcite.rex.RexNode> targets, org.apache.calcite.rex.RexNode e)
Removes all expressions from a list that are equivalent to a given expression.static org.apache.calcite.rex.RexNode
removeCast(org.apache.calcite.rex.RexNode e)
Removes any casts.static org.apache.calcite.rex.RexNode
removeNullabilityCast(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.rex.RexNode node)
Removes any casts that change nullability but not type.static boolean
requiresDecimalExpansion(List<org.apache.calcite.rex.RexNode> operands, boolean recurse)
Determines whether any operand of a set requires decimal expansion.static boolean
requiresDecimalExpansion(org.apache.calcite.rex.RexNode expr, boolean recurse)
Determines whether aRexCall
requires decimal expansion.static boolean
requiresDecimalExpansion(org.apache.calcite.rex.RexProgram program, boolean recurse)
Returns whether aRexProgram
contains expressions which require decimal expansion.static List<org.apache.calcite.rex.RexNode>
retainDeterministic(List<org.apache.calcite.rex.RexNode> list)
static <C extends Comparable<C>>
org.apache.calcite.rex.RexNodesargRef(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode ref, org.apache.calcite.util.Sarg<C> sarg, org.apache.calcite.rel.type.RelDataType type, org.apache.calcite.rex.RexUnknownAs unknownAs)
static org.apache.calcite.rex.RexShuttle
searchShuttle(org.apache.calcite.rex.RexBuilder rexBuilder, @Nullable org.apache.calcite.rex.RexProgram program, int maxComplexity)
Creates a shuttle that expands calls toSqlStdOperatorTable.SEARCH
.static List<org.apache.calcite.rex.RexNode>
shift(Iterable<org.apache.calcite.rex.RexNode> nodes, int offset)
Shifts everyRexInputRef
in an expression byoffset
.static org.apache.calcite.rex.RexNode
shift(org.apache.calcite.rex.RexNode node, int offset)
Shifts everyRexInputRef
in an expression byoffset
.static org.apache.calcite.rex.RexNode
shift(org.apache.calcite.rex.RexNode node, int start, int offset)
Shifts everyRexInputRef
in an expression higher thanstart
byoffset
.static <C extends Comparable<C>>
org.apache.calcite.rex.RexNodesimpleSarg(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode ref, org.apache.calcite.util.Sarg<C> sarg, org.apache.calcite.rex.RexUnknownAs unknownAs)
Expands an 'all' or 'none' sarg.static org.apache.calcite.rex.RexNode
simplify(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e)
Deprecated.Create aRexSimplify
, then call itsRexSimplify.simplify(RexNode, RexUnknownAs)
method.static org.apache.calcite.rex.RexNode
simplify(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e, boolean unknownAsFalse)
Deprecated.Create aRexSimplify
, then call itsRexSimplify.simplify(RexNode, RexUnknownAs)
method.static org.apache.calcite.rex.RexNode
simplifyAnd(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexCall e, boolean unknownAsFalse)
Deprecated.static org.apache.calcite.rex.RexNode
simplifyAnd2(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> terms, List<org.apache.calcite.rex.RexNode> notTerms)
Deprecated.static org.apache.calcite.rex.RexNode
simplifyAnd2ForUnknownAsFalse(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> terms, List<org.apache.calcite.rex.RexNode> notTerms)
Deprecated.static org.apache.calcite.rex.RexNode
simplifyAnds(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Deprecated.UseRexSimplify.simplifyAnds(Iterable, RexUnknownAs)
.static org.apache.calcite.rex.RexNode
simplifyAnds(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends org.apache.calcite.rex.RexNode> nodes, boolean unknownAsFalse)
Deprecated.static org.apache.calcite.rex.RexNode
simplifyOr(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexCall call)
Deprecated.static org.apache.calcite.rex.RexNode
simplifyOrs(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> terms)
Deprecated.static org.apache.calcite.rex.RexNode
simplifyPreservingType(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e)
Deprecated.UseRexSimplify.simplifyPreservingType(RexNode)
, which allows you to specify anRexExecutor
.static List<String>
strings(List<org.apache.calcite.rex.RexNode> list)
Transforms a list of expressions to the list of digests.static org.apache.calcite.rex.RexNode
swapColumnReferences(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node, Map<org.apache.calcite.rex.RexTableInputRef,Set<org.apache.calcite.rex.RexTableInputRef>> ec)
Given an expression, it will swap its column referencesRexTableInputRef
using the contents in the map (in particular, the first element of the set in the map value).static org.apache.calcite.rex.RexNode
swapColumnTableReferences(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node, Map<org.apache.calcite.rex.RexTableInputRef,? extends @Nullable Set<org.apache.calcite.rex.RexTableInputRef>> ec, @Nullable Map<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> tableMapping)
Given an expression, it will swap the column referencesRexTableInputRef
using the contents in the first map (in particular, the first element of the set in the map value), and then it will swap the table references contained in itsRexTableInputRef
using the contents in the second map.static org.apache.calcite.rex.RexNode
swapTableColumnReferences(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node, @Nullable Map<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> tableMapping, @Nullable Map<org.apache.calcite.rex.RexTableInputRef,Set<org.apache.calcite.rex.RexTableInputRef>> ec)
Given an expression, it will swap the table references contained in itsRexTableInputRef
using the contents in the first map, and then it will swap the column referencesRexTableInputRef
using the contents in the second map (in particular, the first element of the set in the map value).static org.apache.calcite.rex.RexNode
swapTableReferences(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node, Map<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> tableMapping)
Given an expression, it will swap the table references contained in itsRexTableInputRef
using the contents in the map.static org.apache.calcite.rex.RexNode
toCnf(org.apache.calcite.rex.RexBuilder rexBuilder, int maxCnfNodeCount, org.apache.calcite.rex.RexNode rex)
Similar totoCnf(RexBuilder, RexNode)
; however, it lets you specify a threshold in the number of nodes that can be created out of the conversion.static org.apache.calcite.rex.RexNode
toCnf(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode rex)
Converts an expression to conjunctive normal form (CNF).static org.apache.calcite.rex.RexNode
toDnf(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode rex)
Converts an expression to disjunctive normal form (DNF).static List<org.apache.calcite.rel.type.RelDataType>
types(List<? extends org.apache.calcite.rex.RexNode> nodes)
Transforms a list of expressions into a list of their types.
-
-
-
Method Detail
-
getSelectivity
public static double getSelectivity(@Nullable org.apache.calcite.rex.RexNode exp)
Returns a guess for the selectivity of an expression.- Parameters:
exp
- expression of interest, or null for none (implying a selectivity of 1.0)- Returns:
- guessed selectivity
-
generateCastExpressions
public static List<org.apache.calcite.rex.RexNode> generateCastExpressions(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rel.type.RelDataType lhsRowType, org.apache.calcite.rel.type.RelDataType rhsRowType)
Generates a cast from one row type to another.- Parameters:
rexBuilder
- RexBuilder to use for constructing castslhsRowType
- target row typerhsRowType
- source row type; fields must be 1-to-1 with lhsRowType, in same order- Returns:
- cast expressions
-
generateCastExpressions
public static List<org.apache.calcite.rex.RexNode> generateCastExpressions(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rel.type.RelDataType lhsRowType, List<org.apache.calcite.rex.RexNode> rhsExps)
Generates a cast for a row type.- Parameters:
rexBuilder
- RexBuilder to use for constructing castslhsRowType
- target row typerhsExps
- expressions to be cast- Returns:
- cast expressions
-
isNullLiteral
public static boolean isNullLiteral(org.apache.calcite.rex.RexNode node, boolean allowCast)
Returns whether a node represents the NULL value.Examples:
- For
RexLiteral
Unknown, returns false. - For
CAST(NULL AS type)
, returns true ifallowCast
is true, false otherwise. - For
CAST(CAST(NULL AS type) AS type))
, returns false.
- For
-
isNull
public static boolean isNull(org.apache.calcite.rex.RexNode expr)
Returns whether a node represents the NULL value or a series of nestedCAST(NULL AS type)
calls. For example:isNull(CAST(CAST(NULL as INTEGER) AS VARCHAR(1)))
returnstrue
.
-
isSymbolLiteral
public static boolean isSymbolLiteral(org.apache.calcite.rex.RexNode expr)
Returns whether a node represents aSqlTypeName.SYMBOL
literal.
-
isLiteral
public static boolean isLiteral(org.apache.calcite.rex.RexNode node, boolean allowCast)
Returns whether a node represents a literal.Examples:
- For
CAST(literal AS type)
, returns true ifallowCast
is true, false otherwise. - For
CAST(CAST(literal AS type) AS type))
, returns false.
- Parameters:
node
- The node, never null.allowCast
- whether to regard CAST(literal) as a literal- Returns:
- Whether the node is a literal
- For
-
allLiterals
public static boolean allLiterals(List<org.apache.calcite.rex.RexNode> expressionOperands)
Returns whether every expression in a list is a literal.- Parameters:
expressionOperands
- list of expressions to check- Returns:
- true if every expression from the specified list is literal.
-
isReferenceOrAccess
public static boolean isReferenceOrAccess(org.apache.calcite.rex.RexNode node, boolean allowCast)
Returns whether a node represents an input reference or field access.- Parameters:
node
- The node, never null.allowCast
- whether to regard CAST(x) as true- Returns:
- Whether the node is a reference or access
-
isNullabilityCast
public static boolean isNullabilityCast(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.rex.RexNode node)
Returns whether an expression is a cast just for the purposes of nullability, not changing any other aspect of the type.
-
removeNullabilityCast
public static org.apache.calcite.rex.RexNode removeNullabilityCast(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.rex.RexNode node)
Removes any casts that change nullability but not type.For example,
CAST(1 = 0 AS BOOLEAN)
becomes1 = 0
.
-
removeCast
public static org.apache.calcite.rex.RexNode removeCast(org.apache.calcite.rex.RexNode e)
Removes any casts.For example,
CAST('1' AS INTEGER)
becomes'1'
.
-
predicateConstants
public static <C extends org.apache.calcite.rex.RexNode> com.google.common.collect.ImmutableMap<org.apache.calcite.rex.RexNode,C> predicateConstants(Class<C> clazz, org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> predicates)
Creates a map containing each (e, constant) pair that occurs within a predicate list.- Type Parameters:
C
- what to consider a constant:RexLiteral
to use a narrow definition of constant, orRexNode
to useisConstant(RexNode)
- Parameters:
clazz
- Class of expression that is considered constantrexBuilder
- Rex builderpredicates
- Predicate list- Returns:
- Map from values to constants
-
nodeCount
public static int nodeCount(List<? extends org.apache.calcite.rex.RexNode> nodes)
Returns the number of nodes (including leaves) in a list of expressions.- See Also:
RexNode.nodeCount()
-
find
public static RexUtil.RexFinder find(org.apache.calcite.sql.SqlKind kind)
Returns a visitor that finds nodes of a givenSqlKind
.
-
find
public static RexUtil.RexFinder find(Set<org.apache.calcite.sql.SqlKind> kinds)
Returns a visitor that finds nodes of givenSqlKind
s.
-
find
public static RexUtil.RexFinder find(org.apache.calcite.rex.RexInputRef ref)
Returns a visitor that finds a particularRexInputRef
.
-
expandSearch
public static org.apache.calcite.rex.RexNode expandSearch(org.apache.calcite.rex.RexBuilder rexBuilder, @Nullable org.apache.calcite.rex.RexProgram program, org.apache.calcite.rex.RexNode node)
Expands all the calls toSqlStdOperatorTable.SEARCH
in an expression.
-
expandSearch
public static org.apache.calcite.rex.RexNode expandSearch(org.apache.calcite.rex.RexBuilder rexBuilder, @Nullable org.apache.calcite.rex.RexProgram program, org.apache.calcite.rex.RexNode node, int maxComplexity)
Expands calls toSqlStdOperatorTable.SEARCH
whose complexity is greater thanmaxComplexity
in an expression.
-
searchShuttle
public static org.apache.calcite.rex.RexShuttle searchShuttle(org.apache.calcite.rex.RexBuilder rexBuilder, @Nullable org.apache.calcite.rex.RexProgram program, int maxComplexity)
Creates a shuttle that expands calls toSqlStdOperatorTable.SEARCH
.If
maxComplexity
is non-negative, aSarg
whose complexity is greater thanmaxComplexity
is retained (not expanded); this gives a means to simplify simple expressions such asx IS NULL
orx > 10
while keeping more complex expressions such asx IN (3, 5, 7) OR x IS NULL
as a Sarg.
-
sargRef
public static <C extends Comparable<C>> org.apache.calcite.rex.RexNode sargRef(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode ref, org.apache.calcite.util.Sarg<C> sarg, org.apache.calcite.rel.type.RelDataType type, org.apache.calcite.rex.RexUnknownAs unknownAs)
-
simpleSarg
public static <C extends Comparable<C>> org.apache.calcite.rex.RexNode simpleSarg(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode ref, org.apache.calcite.util.Sarg<C> sarg, org.apache.calcite.rex.RexUnknownAs unknownAs)
Expands an 'all' or 'none' sarg.
-
isConstant
public static boolean isConstant(org.apache.calcite.rex.RexNode node)
Returns whether node is made up of constants.- Parameters:
node
- Node to inspect- Returns:
- true if node is made up of constants, false otherwise
-
isDeterministic
public static boolean isDeterministic(org.apache.calcite.rex.RexNode e)
Returns whether a given expression is deterministic.- Parameters:
e
- Expression- Returns:
- true if tree result is deterministic, false otherwise
-
retainDeterministic
public static List<org.apache.calcite.rex.RexNode> retainDeterministic(List<org.apache.calcite.rex.RexNode> list)
-
findOperatorCall
public static @Nullable org.apache.calcite.rex.RexCall findOperatorCall(org.apache.calcite.sql.SqlOperator operator, org.apache.calcite.rex.RexNode node)
Returns whether a given node contains a RexCall with a specified operator.- Parameters:
operator
- Operator to look fornode
- a RexNode tree
-
containsInputRef
public static boolean containsInputRef(org.apache.calcite.rex.RexNode node)
Returns whether a given tree contains any {link RexInputRef} nodes.- Parameters:
node
- a RexNode tree
-
containsFieldAccess
public static boolean containsFieldAccess(org.apache.calcite.rex.RexNode node)
Returns whether a given tree contains anyRexFieldAccess
nodes.- Parameters:
node
- a RexNode tree
-
requiresDecimalExpansion
public static boolean requiresDecimalExpansion(org.apache.calcite.rex.RexNode expr, boolean recurse)
Determines whether aRexCall
requires decimal expansion. It usually requires expansion if it has decimal operands.Exceptions to this rule are:
- isNull doesn't require expansion
- It's okay to cast decimals to and from char types
- It's okay to cast nulls as decimals
- Casts require expansion if their return type is decimal
- Reinterpret casts can handle a decimal operand
- Parameters:
expr
- expression possibly in need of expansionrecurse
- whether to check nested calls- Returns:
- whether the expression requires expansion
-
requiresDecimalExpansion
public static boolean requiresDecimalExpansion(List<org.apache.calcite.rex.RexNode> operands, boolean recurse)
Determines whether any operand of a set requires decimal expansion.
-
requiresDecimalExpansion
public static boolean requiresDecimalExpansion(org.apache.calcite.rex.RexProgram program, boolean recurse)
Returns whether aRexProgram
contains expressions which require decimal expansion.
-
canReinterpretOverflow
public static boolean canReinterpretOverflow(org.apache.calcite.rex.RexCall call)
-
containNoCommonExprs
public static boolean containNoCommonExprs(List<org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.util.Litmus litmus)
Returns whether an array of expressions has any common sub-expressions.
-
containNoForwardRefs
public static boolean containNoForwardRefs(List<org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.rel.type.RelDataType inputRowType, org.apache.calcite.util.Litmus litmus)
Returns whether an array of expressions contains no forward references. That is, if expression #i contains aRexInputRef
referencing field i or greater.- Parameters:
exprs
- Array of expressionsinputRowType
- Input row typelitmus
- What to do if an error is detected (there is a forward reference)- Returns:
- Whether there is a forward reference
-
containComplexExprs
public static boolean containComplexExprs(List<org.apache.calcite.rex.RexNode> exprs)
Returns whether a list of expressions contains complex expressions, that is, a call whose arguments are notRexVariable
(or a subtype such asRexInputRef
) orRexLiteral
.
-
containsTableInputRef
public static boolean containsTableInputRef(List<org.apache.calcite.rex.RexNode> nodes)
Returns whether any of the given expression trees contains a {link RexTableInputRef} node.- Parameters:
nodes
- a list of RexNode trees- Returns:
- true if at least one was found, otherwise false
-
containsTableInputRef
public static @Nullable org.apache.calcite.rex.RexTableInputRef containsTableInputRef(org.apache.calcite.rex.RexNode node)
Returns whether a given tree contains any {link RexTableInputRef} nodes.- Parameters:
node
- a RexNode tree- Returns:
- first such node found or null if it there is no such node
-
isAtomic
public static boolean isAtomic(org.apache.calcite.rex.RexNode expr)
-
isCallTo
public static boolean isCallTo(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.SqlOperator op)
Returns whether anode
is acall
to a givenoperator
.
-
createStructType
public static org.apache.calcite.rel.type.RelDataType createStructType(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, List<org.apache.calcite.rex.RexNode> exprs)
Creates a record type with anonymous field names.- Parameters:
typeFactory
- Type factoryexprs
- Expressions- Returns:
- Record type
-
createStructType
public static org.apache.calcite.rel.type.RelDataType createStructType(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, List<? extends org.apache.calcite.rex.RexNode> exprs, @Nullable List<? extends @Nullable String> names, org.apache.calcite.sql.validate.SqlValidatorUtil.Suggester suggester)
Creates a record type with specified field names.The array of field names may be null, or any of the names within it can be null. We recommend using explicit names where possible, because it makes it much easier to figure out the intent of fields when looking at planner output.
- Parameters:
typeFactory
- Type factoryexprs
- Expressionsnames
- Field names, may be null, or elements may be nullsuggester
- Generates alternative names ifnames
is not null and its elements are not unique- Returns:
- Record type
-
createStructType
@Deprecated public static org.apache.calcite.rel.type.RelDataType createStructType(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, List<? extends org.apache.calcite.rex.RexNode> exprs, List<String> names)
Deprecated.
-
compatibleTypes
public static boolean compatibleTypes(List<org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.rel.type.RelDataType type, org.apache.calcite.util.Litmus litmus)
Returns whether the type of an array of expressions is compatible with a struct type.- Parameters:
exprs
- Array of expressionstype
- Typelitmus
- What to do if an error is detected (there is a mismatch)- Returns:
- Whether every expression has the same type as the corresponding member of the struct type
- See Also:
RelOptUtil.eq(String, RelDataType, String, RelDataType, org.apache.calcite.util.Litmus)
-
makeKey
public static org.apache.calcite.util.Pair<org.apache.calcite.rex.RexNode,String> makeKey(org.apache.calcite.rex.RexNode expr)
Creates a key forRexNode
which is the same as another key of another RexNode only if the two have both the same type and textual representation. For example, "10" integer and "10" bigint result in different keys.
-
containIdentity
public static boolean containIdentity(List<? extends org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.rel.type.RelDataType rowType, org.apache.calcite.util.Litmus litmus)
Returns whether the leading edge of a given array of expressions is whollyRexInputRef
objects with types corresponding to the underlying datatype.
-
isIdentity
public static boolean isIdentity(List<? extends org.apache.calcite.rex.RexNode> exps, org.apache.calcite.rel.type.RelDataType inputRowType)
Returns whether a list of expressions projects the incoming fields.
-
composeConjunction
public static org.apache.calcite.rex.RexNode composeConjunction(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends @Nullable org.apache.calcite.rex.RexNode> nodes)
AscomposeConjunction(RexBuilder, Iterable, boolean)
but never returns null.
-
composeConjunction
public static @Nullable org.apache.calcite.rex.RexNode composeConjunction(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends @Nullable org.apache.calcite.rex.RexNode> nodes, boolean nullOnEmpty)
Converts a collection of expressions into an AND. If there are zero expressions, returns TRUE. If there is one expression, returns just that expression. If any of the expressions are FALSE, returns FALSE. Removes expressions that always evaluate to TRUE. Returns null only ifnullOnEmpty
and expression is TRUE.
-
flattenAnd
public static com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> flattenAnd(Iterable<? extends @Nullable org.apache.calcite.rex.RexNode> nodes)
Flattens a list of AND nodes.Treats null nodes as literal TRUE (i.e. ignores them).
-
composeDisjunction
public static org.apache.calcite.rex.RexNode composeDisjunction(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Converts a collection of expressions into an OR. If there are zero expressions, returns FALSE. If there is one expression, returns just that expression. If any of the expressions are TRUE, returns TRUE. Removes expressions that always evaluate to FALSE. Flattens expressions that are ORs.
-
composeDisjunction
public static @Nullable org.apache.calcite.rex.RexNode composeDisjunction(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends org.apache.calcite.rex.RexNode> nodes, boolean nullOnEmpty)
Converts a collection of expressions into an OR, optionally returning null if the list is empty.
-
flattenOr
public static com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> flattenOr(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Flattens a list of OR nodes.
-
apply
public static List<org.apache.calcite.rel.RelCollation> apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, List<org.apache.calcite.rel.RelCollation> collationList)
Applies a mapping to a collation list.- Parameters:
mapping
- MappingcollationList
- Collation list- Returns:
- collation list with mapping applied to each field
-
apply
public static org.apache.calcite.rel.RelCollation apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, org.apache.calcite.rel.RelCollation collation)
Applies a mapping to a collation.- Parameters:
mapping
- Mappingcollation
- Collation- Returns:
- collation with mapping applied
-
apply
public static @Nullable org.apache.calcite.rel.RelFieldCollation apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, org.apache.calcite.rel.RelFieldCollation fieldCollation)
Applies a mapping to a field collation.If the field is not mapped, returns null.
- Parameters:
mapping
- MappingfieldCollation
- Field collation- Returns:
- collation with mapping applied
-
applyFields
public static List<org.apache.calcite.rel.RelFieldCollation> applyFields(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, List<org.apache.calcite.rel.RelFieldCollation> fieldCollations)
Applies a mapping to a list of field collations.- Parameters:
mapping
- MappingfieldCollations
- Field collations- Returns:
- collations with mapping applied
-
apply
public static org.apache.calcite.rex.RexNode apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, org.apache.calcite.rex.RexNode node)
Applies a mapping to an expression.
-
apply
public static List<org.apache.calcite.rex.RexNode> apply(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Applies a mapping to an iterable over expressions.
-
apply
public static <T extends org.apache.calcite.rex.RexNode> T[] apply(org.apache.calcite.rex.RexVisitor<T> shuttle, T[] exprs)
Applies a shuttle to an array of expressions. Creates a copy first.- Parameters:
shuttle
- Shuttleexprs
- Array of expressions
-
apply
public static void apply(org.apache.calcite.rex.RexVisitor<Void> visitor, org.apache.calcite.rex.RexNode[] exprs, @Nullable org.apache.calcite.rex.RexNode expr)
Applies a visitor to an array of expressions and, if specified, a single expression.- Parameters:
visitor
- Visitorexprs
- Array of expressionsexpr
- Single expression, may be null
-
apply
public static void apply(org.apache.calcite.rex.RexVisitor<Void> visitor, List<? extends org.apache.calcite.rex.RexNode> exprs, @Nullable org.apache.calcite.rex.RexNode expr)
Applies a visitor to a list of expressions and, if specified, a single expression.- Parameters:
visitor
- Visitorexprs
- List of expressionsexpr
- Single expression, may be null
-
flatten
public static org.apache.calcite.rex.RexNode flatten(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node)
Flattens an expression.Returns the same expression if it is already flat.
-
flatten
public static List<org.apache.calcite.rex.RexNode> flatten(List<? extends org.apache.calcite.rex.RexNode> exprs, org.apache.calcite.sql.SqlOperator op)
Converts a list of operands into a list that is flat with respect to the given operator. The operands are assumed to be flat already.
-
isFlat
public static boolean isFlat(org.apache.calcite.rex.RexNode expr)
Returns false if the expression can be optimized by flattening calls to an associative operator such as AND and OR.
-
isLosslessCast
public static boolean isLosslessCast(org.apache.calcite.rex.RexNode node)
Returns whether the input is a 'loss-less' cast, that is, a cast from which the original value of the field can be certainly recovered.For instance, int → bigint is loss-less (as you can cast back to int without loss of information), but bigint → int is not loss-less.
The implementation of this method does not return false positives. However, it is not complete.
- Parameters:
node
- input node to verify if it represents a loss-less cast- Returns:
- true iff the node is a loss-less cast
-
isLosslessCast
@API(since="1.22", status=EXPERIMENTAL) public static boolean isLosslessCast(org.apache.calcite.rel.type.RelDataType source, org.apache.calcite.rel.type.RelDataType target)
Returns whether the conversion fromsource
totarget
type is a 'loss-less' cast, that is, a cast from which the original value of the field can be certainly recovered.For instance, int → bigint is loss-less (as you can cast back to int without loss of information), but bigint → int is not loss-less.
The implementation of this method does not return false positives. However, it is not complete.
- Parameters:
source
- source typetarget
- target type- Returns:
- true iff the conversion is a loss-less cast
-
toCnf
public static org.apache.calcite.rex.RexNode toCnf(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode rex)
Converts an expression to conjunctive normal form (CNF).The following expression is in CNF:
(a OR b) AND (c OR d)
The following expression is not in CNF:
(a AND b) OR c
but can be converted to CNF:
(a OR c) AND (b OR c)
The following expression is not in CNF:
NOT (a OR NOT b)
but can be converted to CNF by applying de Morgan's theorem:
NOT a AND b
Expressions not involving AND, OR or NOT at the top level are in CNF.
-
toCnf
public static org.apache.calcite.rex.RexNode toCnf(org.apache.calcite.rex.RexBuilder rexBuilder, int maxCnfNodeCount, org.apache.calcite.rex.RexNode rex)
Similar totoCnf(RexBuilder, RexNode)
; however, it lets you specify a threshold in the number of nodes that can be created out of the conversion.If the number of resulting nodes exceeds that threshold, stops conversion and returns the original expression.
If the threshold is negative it is ignored.
Leaf nodes in the expression do not count towards the threshold.
-
toDnf
public static org.apache.calcite.rex.RexNode toDnf(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode rex)
Converts an expression to disjunctive normal form (DNF).DNF: It is a form of logical formula which is disjunction of conjunctive clauses.
All logical formulas can be converted into DNF.
The following expression is in DNF:
(a AND b) OR (c AND d)
The following expression is not in CNF:
(a OR b) AND c
but can be converted to DNF:
(a AND c) OR (b AND c)
The following expression is not in CNF:
NOT (a OR NOT b)
but can be converted to DNF by applying de Morgan's theorem:
NOT a AND b
Expressions not involving AND, OR or NOT at the top level are in DNF.
-
exists
public static <E> boolean exists(List<? extends E> list, org.apache.calcite.linq4j.function.Predicate1<E> predicate)
Returns whether there is an element inlist
for whichpredicate
is true.
-
all
public static <E> boolean all(List<? extends E> list, org.apache.calcite.linq4j.function.Predicate1<E> predicate)
Returns whetherpredicate
is true for all elements oflist
.
-
shift
public static org.apache.calcite.rex.RexNode shift(org.apache.calcite.rex.RexNode node, int offset)
Shifts everyRexInputRef
in an expression byoffset
.
-
shift
public static List<org.apache.calcite.rex.RexNode> shift(Iterable<org.apache.calcite.rex.RexNode> nodes, int offset)
Shifts everyRexInputRef
in an expression byoffset
.
-
shift
public static org.apache.calcite.rex.RexNode shift(org.apache.calcite.rex.RexNode node, int start, int offset)
Shifts everyRexInputRef
in an expression higher thanstart
byoffset
.
-
pullFactors
public static org.apache.calcite.rex.RexNode pullFactors(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node)
Creates an equivalent version of a node where common factors among ORs are pulled up.For example,
(a AND b) OR (a AND c AND d)
becomes
a AND (b OR (c AND d))
Note that this result is not in CNF (see
toCnf(RexBuilder, RexNode)
) because there is an AND inside an OR.This form is useful if, say,
a
contains columns from only the left-hand side of a join, and can be pushed to the left input.- Parameters:
rexBuilder
- Rex buildernode
- Expression to transform- Returns:
- Equivalent expression with common factors pulled up
-
fixUp
@Deprecated public static List<org.apache.calcite.rex.RexNode> fixUp(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> nodes, org.apache.calcite.rel.type.RelDataType rowType)
Deprecated.
-
fixUp
public static List<org.apache.calcite.rex.RexNode> fixUp(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> nodes, List<org.apache.calcite.rel.type.RelDataType> fieldTypes)
Fixes up the type of allRexInputRef
s in an expression to match differences in nullability.Such differences in nullability occur when expressions are moved through outer joins.
Throws if there any greater inconsistencies of type.
-
types
public static List<org.apache.calcite.rel.type.RelDataType> types(List<? extends org.apache.calcite.rex.RexNode> nodes)
Transforms a list of expressions into a list of their types.
-
families
public static List<org.apache.calcite.rel.type.RelDataTypeFamily> families(List<org.apache.calcite.rel.type.RelDataType> types)
-
removeAll
public static boolean removeAll(List<org.apache.calcite.rex.RexNode> targets, org.apache.calcite.rex.RexNode e)
Removes all expressions from a list that are equivalent to a given expression. Returns whether any were removed.
-
eq
@Deprecated public static boolean eq(org.apache.calcite.rex.RexNode e1, org.apache.calcite.rex.RexNode e2)
Deprecated.Returns whether twoRexNode
s are structurally equal.This method considers structure, not semantics. 'x < y' is not equivalent to 'y > x'.
-
simplifyPreservingType
@Deprecated public static org.apache.calcite.rex.RexNode simplifyPreservingType(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e)
Deprecated.UseRexSimplify.simplifyPreservingType(RexNode)
, which allows you to specify anRexExecutor
.Simplifies a boolean expression, always preserving its type and its nullability.This is useful if you are simplifying expressions in a
Project
.
-
simplify
@Deprecated public static org.apache.calcite.rex.RexNode simplify(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e)
Deprecated.Create aRexSimplify
, then call itsRexSimplify.simplify(RexNode, RexUnknownAs)
method.Simplifies a boolean expression, leaving UNKNOWN values as UNKNOWN, and using the default executor.
-
simplify
@Deprecated public static org.apache.calcite.rex.RexNode simplify(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e, boolean unknownAsFalse)
Deprecated.Create aRexSimplify
, then call itsRexSimplify.simplify(RexNode, RexUnknownAs)
method.Simplifies a boolean expression, using the default executor.In particular:
simplify(x = 1 AND y = 2 AND NOT x = 1)
returnsy = 2
simplify(x = 1 AND FALSE)
returnsFALSE
If the expression is a predicate in a WHERE clause, UNKNOWN values have the same effect as FALSE. In situations like this, specify
unknownAsFalse = true
, so and we can switch from 3-valued logic to simpler 2-valued logic and make more optimizations.- Parameters:
rexBuilder
- Rex buildere
- Expression to simplifyunknownAsFalse
- Whether to convert UNKNOWN values to FALSE
-
simplifyAnds
@Deprecated public static org.apache.calcite.rex.RexNode simplifyAnds(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Deprecated.UseRexSimplify.simplifyAnds(Iterable, RexUnknownAs)
.Simplifies a conjunction of boolean expressions.
-
simplifyAnds
@Deprecated public static org.apache.calcite.rex.RexNode simplifyAnds(org.apache.calcite.rex.RexBuilder rexBuilder, Iterable<? extends org.apache.calcite.rex.RexNode> nodes, boolean unknownAsFalse)
Deprecated.
-
not
public static org.apache.calcite.rex.RexNode not(org.apache.calcite.rex.RexNode e)
Negates a logical expression by adding or removing a NOT.
-
op
@API(since="1.27.0", status=EXPERIMENTAL) public static org.apache.calcite.sql.SqlOperator op(org.apache.calcite.sql.SqlKind kind)
-
simplifyAnd
@Deprecated public static org.apache.calcite.rex.RexNode simplifyAnd(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexCall e, boolean unknownAsFalse)
Deprecated.
-
simplifyAnd2
@Deprecated public static org.apache.calcite.rex.RexNode simplifyAnd2(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> terms, List<org.apache.calcite.rex.RexNode> notTerms)
Deprecated.
-
simplifyAnd2ForUnknownAsFalse
@Deprecated public static org.apache.calcite.rex.RexNode simplifyAnd2ForUnknownAsFalse(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> terms, List<org.apache.calcite.rex.RexNode> notTerms)
Deprecated.
-
negate
public static @Nullable org.apache.calcite.rex.RexNode negate(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexCall call)
-
invert
public static @Nullable org.apache.calcite.rex.RexNode invert(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexCall call)
-
simplifyOr
@Deprecated public static org.apache.calcite.rex.RexNode simplifyOr(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexCall call)
Deprecated.
-
simplifyOrs
@Deprecated public static org.apache.calcite.rex.RexNode simplifyOrs(org.apache.calcite.rex.RexBuilder rexBuilder, List<org.apache.calcite.rex.RexNode> terms)
Deprecated.
-
andNot
public static org.apache.calcite.rex.RexNode andNot(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e, org.apache.calcite.rex.RexNode... notTerms)
Creates the expressione1 AND NOT notTerm1 AND NOT notTerm2 ...
.
-
andNot
public static org.apache.calcite.rex.RexNode andNot(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode e, Iterable<? extends org.apache.calcite.rex.RexNode> notTerms)
Creates the expressione1 AND NOT notTerm1 AND NOT notTerm2 ...
.Examples:
- andNot(p) returns "p"
- andNot(p, n1, n2) returns "p AND NOT n1 AND NOT n2"
- andNot(x = 10, x = 20, y = 30, x = 30) returns "x = 10 AND NOT (y = 30)"
-
isCasePredicate
public static boolean isCasePredicate(org.apache.calcite.rex.RexCall call, int i)
Returns whether a given operand of a CASE expression is a predicate.A switched case (CASE x WHEN x1 THEN v1 ... ELSE e END) has an even number of arguments and odd-numbered arguments are predicates.
A condition case (CASE WHEN p1 THEN v1 ... ELSE e END) has an odd number of arguments and even-numbered arguments are predicates, except for the last argument.
-
notFn
@Deprecated public static com.google.common.base.Function<org.apache.calcite.rex.RexNode,org.apache.calcite.rex.RexNode> notFn(org.apache.calcite.rex.RexBuilder rexBuilder)
Deprecated.Returns a function that applies NOT to its argument.
-
containsCorrelation
public static boolean containsCorrelation(org.apache.calcite.rex.RexNode condition)
Returns whether an expression contains aRexCorrelVariable
.
-
swapTableReferences
public static org.apache.calcite.rex.RexNode swapTableReferences(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node, Map<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> tableMapping)
Given an expression, it will swap the table references contained in itsRexTableInputRef
using the contents in the map.
-
swapColumnReferences
public static org.apache.calcite.rex.RexNode swapColumnReferences(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node, Map<org.apache.calcite.rex.RexTableInputRef,Set<org.apache.calcite.rex.RexTableInputRef>> ec)
Given an expression, it will swap its column referencesRexTableInputRef
using the contents in the map (in particular, the first element of the set in the map value).
-
swapTableColumnReferences
public static org.apache.calcite.rex.RexNode swapTableColumnReferences(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node, @Nullable Map<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> tableMapping, @Nullable Map<org.apache.calcite.rex.RexTableInputRef,Set<org.apache.calcite.rex.RexTableInputRef>> ec)
Given an expression, it will swap the table references contained in itsRexTableInputRef
using the contents in the first map, and then it will swap the column referencesRexTableInputRef
using the contents in the second map (in particular, the first element of the set in the map value).
-
swapColumnTableReferences
public static org.apache.calcite.rex.RexNode swapColumnTableReferences(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexNode node, Map<org.apache.calcite.rex.RexTableInputRef,? extends @Nullable Set<org.apache.calcite.rex.RexTableInputRef>> ec, @Nullable Map<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> tableMapping)
Given an expression, it will swap the column referencesRexTableInputRef
using the contents in the first map (in particular, the first element of the set in the map value), and then it will swap the table references contained in itsRexTableInputRef
using the contents in the second map.
-
gatherTableReferences
public static Set<org.apache.calcite.rex.RexTableInputRef.RelTableRef> gatherTableReferences(List<org.apache.calcite.rex.RexNode> nodes)
Gather all table references in input expressions.- Parameters:
nodes
- expressions- Returns:
- set of table references
-
getNonConstColumns
public static org.apache.calcite.util.ImmutableBitSet getNonConstColumns(List<org.apache.calcite.rex.RexNode> expressions)
Given some expressions, gets the indices of the non-constant ones.
-
getNonConstColumns
public static org.apache.calcite.util.ImmutableBitSet getNonConstColumns(org.apache.calcite.util.ImmutableBitSet columns, List<org.apache.calcite.rex.RexNode> expressions)
Given some expressions and columns, gets the indices of the non-constant ones.
-
-