public class RexUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
RexUtil.CnfHelper
|
(package private) static class |
RexUtil.ConstantFinder
Walks over an expression and determines whether it is constant.
|
private static class |
RexUtil.CorrelationFinder
Visitor that throws
Util.FoundOne if
applied to an expression that contains a RexCorrelVariable . |
private static class |
RexUtil.DnfHelper
|
private static class |
RexUtil.ExpressionNormalizer
Walks over expressions and builds a bank of common sub-expressions.
|
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.
|
private static class |
RexUtil.ForwardRefFinder
Walks over an expression and throws an exception if it finds an
RexInputRef with an ordinal beyond the number of fields in the
input row type, or a RexLocalRef with ordinal greater than that set
using RexUtil.ForwardRefFinder.setLimit(int) . |
private static class |
RexUtil.RexShiftShuttle
Shuttle that adds
offset to each RexInputRef in an
expression. |
static class |
RexUtil.SubQueryFinder
Visitor that throws
Util.FoundOne if
applied to an expression that contains a RexSubQuery . |
Modifier and Type | Field and Description |
---|---|
static RexExecutor |
EXECUTOR
Executor for a bit of constant reduction.
|
Modifier | Constructor and Description |
---|---|
private |
RexUtil() |
Modifier and Type | Method and Description |
---|---|
private static void |
addAnd(com.google.common.collect.ImmutableList.Builder<RexNode> builder,
java.util.Set<RexNode> digests,
RexNode node) |
private static RexNode |
addNot(RexNode e) |
private static void |
addOr(com.google.common.collect.ImmutableList.Builder<RexNode> builder,
java.util.Set<RexNode> set,
RexNode node) |
static <E> boolean |
all(java.util.List<? extends E> list,
Predicate1<E> predicate)
Returns whether
predicate is true for all elements of
list . |
static boolean |
allLiterals(java.util.List<RexNode> expressionOperands)
Returns whether every expression in a list is a literal.
|
static RexNode |
andNot(RexBuilder rexBuilder,
RexNode e,
java.lang.Iterable<? extends RexNode> notTerms)
Creates the expression
e1 AND NOT notTerm1 AND NOT notTerm2 ... . |
static RexNode |
andNot(RexBuilder rexBuilder,
RexNode e,
RexNode... notTerms)
Creates the expression
e1 AND NOT notTerm1 AND NOT notTerm2 ... . |
static java.lang.Iterable<RexNode> |
apply(Mappings.TargetMapping mapping,
java.lang.Iterable<? extends RexNode> nodes)
Applies a mapping to an iterable over expressions.
|
static java.util.List<RelCollation> |
apply(Mappings.TargetMapping mapping,
java.util.List<RelCollation> collationList)
Applies a mapping to a collation list.
|
static RelCollation |
apply(Mappings.TargetMapping mapping,
RelCollation collation)
Applies a mapping to a collation.
|
static RelFieldCollation |
apply(Mappings.TargetMapping mapping,
RelFieldCollation fieldCollation)
Applies a mapping to a field collation.
|
static RexNode |
apply(Mappings.TargetMapping mapping,
RexNode node)
Applies a mapping to an expression.
|
static <T extends RexNode> |
apply(RexVisitor<T> shuttle,
T[] exprs)
Applies a shuttle to an array of expressions.
|
static void |
apply(RexVisitor<java.lang.Void> visitor,
java.util.List<? extends RexNode> exprs,
RexNode expr)
Applies a visitor to a list of expressions and, if specified, a single
expression.
|
static void |
apply(RexVisitor<java.lang.Void> visitor,
RexNode[] exprs,
RexNode expr)
Applies a visitor to an array of expressions and, if specified, a single
expression.
|
static java.util.List<RelFieldCollation> |
applyFields(Mappings.TargetMapping mapping,
java.util.List<RelFieldCollation> fieldCollations)
Applies a mapping to a list of field collations.
|
private static boolean |
canAssignFrom(RelDataType type1,
RelDataType type2)
Returns whether a value of
type2 can be assigned to a variable
of type1 . |
static boolean |
canReinterpretOverflow(RexCall call) |
static boolean |
compatibleTypes(java.util.List<RexNode> exprs,
RelDataType type,
Litmus litmus)
Returns whether the type of an array of expressions is compatible with a
struct type.
|
static RexNode |
composeConjunction(RexBuilder rexBuilder,
java.lang.Iterable<? extends RexNode> nodes)
As
composeConjunction(RexBuilder, Iterable, boolean) but never
returns null. |
static RexNode |
composeConjunction(RexBuilder rexBuilder,
java.lang.Iterable<? extends RexNode> nodes,
boolean nullOnEmpty)
Converts a collection of expressions into an AND.
|
static RexNode |
composeDisjunction(RexBuilder rexBuilder,
java.lang.Iterable<? extends RexNode> nodes)
Converts a collection of expressions into an OR.
|
static RexNode |
composeDisjunction(RexBuilder rexBuilder,
java.lang.Iterable<? extends RexNode> nodes,
boolean nullOnEmpty)
Converts a collection of expressions into an OR,
optionally returning null if the list is empty.
|
static boolean |
containComplexExprs(java.util.List<RexNode> exprs)
Returns whether a list of expressions contains complex expressions, that
is, a call whose arguments are not
RexVariable (or a subtype such
as RexInputRef ) or RexLiteral . |
static boolean |
containIdentity(java.util.List<? extends RexNode> exprs,
RelDataType rowType,
Litmus litmus)
Returns whether the leading edge of a given array of expressions is
wholly
RexInputRef objects with types corresponding to the
underlying datatype. |
static boolean |
containNoCommonExprs(java.util.List<RexNode> exprs,
Litmus litmus)
Returns whether an array of expressions has any common sub-expressions.
|
static boolean |
containNoForwardRefs(java.util.List<RexNode> exprs,
RelDataType inputRowType,
Litmus litmus)
Returns whether an array of expressions contains no forward references.
|
(package private) static boolean |
containNoNonTrivialAggs(java.util.List<RexNode> exprs,
Litmus litmus)
Returns whether an array of exp contains no aggregate function calls whose
arguments are not
RexInputRef s. |
static boolean |
containsCorrelation(RexNode condition)
Returns whether an expression contains a
RexCorrelVariable . |
private static boolean |
containsFalse(java.lang.Iterable<RexNode> nodes) |
static boolean |
containsFieldAccess(RexNode node)
Returns whether a given tree contains any
RexFieldAccess nodes. |
static boolean |
containsInputRef(RexNode node)
Returns whether a given tree contains any {link RexInputRef} nodes.
|
static boolean |
containsTableInputRef(java.util.List<RexNode> nodes)
Returns whether any of the given expression trees contains a
{link RexTableInputRef} node.
|
static RexTableInputRef |
containsTableInputRef(RexNode node)
Returns whether a given tree contains any {link RexTableInputRef} nodes.
|
private static boolean |
containsTrue(java.lang.Iterable<RexNode> nodes) |
static RelDataType |
createStructType(RelDataTypeFactory typeFactory,
java.util.List<? extends RexNode> exprs,
java.util.List<java.lang.String> names)
Deprecated.
|
static RelDataType |
createStructType(RelDataTypeFactory typeFactory,
java.util.List<? extends RexNode> exprs,
java.util.List<java.lang.String> names,
SqlValidatorUtil.Suggester suggester)
Creates a record type with specified field names.
|
static RelDataType |
createStructType(RelDataTypeFactory typeFactory,
java.util.List<RexNode> exprs)
Creates a record type with anonymous field names.
|
private static void |
decompose(java.util.Set<RexNode> set,
RexNode rexNode)
Tries to decompose the RexNode which is a RexCall into non-literal
RexNodes.
|
static boolean |
eq(RexNode e1,
RexNode e2)
Deprecated.
|
static <E> boolean |
exists(java.util.List<? extends E> list,
Predicate1<E> predicate)
Returns whether there is an element in
list for which
predicate is true. |
static java.util.List<RelDataTypeFamily> |
families(java.util.List<RelDataType> types) |
static RexCall |
findOperatorCall(SqlOperator operator,
RexNode node)
Returns whether a given node contains a RexCall with a specified operator
|
static java.util.List<RexNode> |
fixUp(RexBuilder rexBuilder,
java.util.List<RexNode> nodes,
java.util.List<RelDataType> fieldTypes)
Fixes up the type of all
RexInputRef s in an
expression to match differences in nullability. |
static java.util.List<RexNode> |
fixUp(RexBuilder rexBuilder,
java.util.List<RexNode> nodes,
RelDataType rowType)
Deprecated.
|
static java.util.List<RexNode> |
flatten(java.util.List<? extends RexNode> exprs,
SqlOperator op)
Converts a list of operands into a list that is flat with respect to
the given operator.
|
static RexNode |
flatten(RexBuilder rexBuilder,
RexNode node)
Flattens an expression.
|
static com.google.common.collect.ImmutableList<RexNode> |
flattenAnd(java.lang.Iterable<? extends RexNode> nodes)
Flattens a list of AND nodes.
|
static com.google.common.collect.ImmutableList<RexNode> |
flattenOr(java.lang.Iterable<? extends RexNode> nodes)
Flattens a list of OR nodes.
|
private static void |
flattenRecurse(java.util.List<RexNode> list,
java.util.List<? extends RexNode> exprs,
SqlOperator op) |
private static <C extends RexNode> |
gatherConstraint(java.lang.Class<C> clazz,
RexNode left,
RexNode right,
java.util.Map<RexNode,C> map,
java.util.Set<RexNode> excludeSet,
RexBuilder rexBuilder) |
private static <C extends RexNode> |
gatherConstraints(java.lang.Class<C> clazz,
RexNode predicate,
java.util.Map<RexNode,C> map,
java.util.Set<RexNode> excludeSet,
RexBuilder rexBuilder) |
static java.util.Set<RexTableInputRef.RelTableRef> |
gatherTableReferences(java.util.List<RexNode> nodes)
Gather all table references in input expressions.
|
static java.util.List<RexNode> |
generateCastExpressions(RexBuilder rexBuilder,
RelDataType lhsRowType,
java.util.List<RexNode> rhsExps)
Generates a cast for a row type.
|
static java.util.List<RexNode> |
generateCastExpressions(RexBuilder rexBuilder,
RelDataType lhsRowType,
RelDataType rhsRowType)
Generates a cast from one row type to another
|
static double |
getSelectivity(RexNode exp)
Returns a guess for the selectivity of an expression.
|
static RexNode |
invert(RexBuilder rexBuilder,
RexCall call) |
private static boolean |
isAssociative(SqlOperator op)
Returns whether an operator is associative.
|
static boolean |
isAtomic(RexNode expr) |
static boolean |
isCallTo(RexNode expr,
SqlOperator op)
|
static boolean |
isCasePredicate(RexCall call,
int i)
Returns whether a given operand of a CASE expression is a predicate.
|
static boolean |
isConstant(RexNode node)
Returns whether node is made up of constants.
|
static boolean |
isDeterministic(RexNode e)
Returns whether a given expression is deterministic.
|
private static boolean |
isFlat(java.util.List<? extends RexNode> exprs,
SqlOperator op)
Returns whether a call to
op with exprs as arguments
would be considered "flat". |
static boolean |
isFlat(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(java.util.List<? extends RexNode> exps,
RelDataType inputRowType)
Returns whether a list of expressions projects the incoming fields.
|
static boolean |
isLiteral(RexNode node,
boolean allowCast)
Returns whether a node represents a literal.
|
static boolean |
isLosslessCast(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(RexNode expr)
Returns whether a node represents the NULL value or a series of nested
CAST(NULL AS type) calls. |
static boolean |
isNullabilityCast(RelDataTypeFactory typeFactory,
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(RexNode node,
boolean allowCast)
Returns whether a node represents the NULL value.
|
static boolean |
isReferenceOrAccess(RexNode node,
boolean allowCast)
Returns whether a node represents an input reference or field access.
|
static Pair<RexNode,java.lang.String> |
makeKey(RexNode expr)
Creates a key for
RexNode which is the same as another key of
another RexNode only if the two have both the same type and textual
representation. |
static RexNode |
negate(RexBuilder rexBuilder,
RexCall call) |
(package private) static RexNode |
not(RexBuilder rexBuilder,
RexNode input)
Applies NOT to an expression.
|
static RexNode |
not(RexNode e)
Negates a logical expression by adding or removing a NOT.
|
static com.google.common.base.Function<RexNode,RexNode> |
notFn(RexBuilder rexBuilder)
Deprecated.
|
(package private) static SqlOperator |
op(SqlKind kind) |
private static boolean |
overlap(RexNode rexNode,
java.util.Set<RexNode> set) |
static <C extends RexNode> |
predicateConstants(java.lang.Class<C> clazz,
RexBuilder rexBuilder,
java.util.List<RexNode> predicates)
Creates a map containing each (e, constant) pair that occurs within
a predicate list.
|
static RexNode |
pullFactors(RexBuilder rexBuilder,
RexNode node)
Creates an equivalent version of a node where common factors among ORs
are pulled up.
|
static boolean |
removeAll(java.util.List<RexNode> targets,
RexNode e)
Removes all expressions from a list that are equivalent to a given
expression.
|
static RexNode |
removeNullabilityCast(RelDataTypeFactory typeFactory,
RexNode node)
Removes any casts that change nullability but not type.
|
static boolean |
requiresDecimalExpansion(java.util.List<RexNode> operands,
boolean recurse)
Determines whether any operand of a set requires decimal expansion
|
static boolean |
requiresDecimalExpansion(RexNode expr,
boolean recurse)
Determines whether a
RexCall requires decimal expansion. |
static boolean |
requiresDecimalExpansion(RexProgram program,
boolean recurse)
Returns whether a
RexProgram contains expressions which require
decimal expansion. |
static java.util.List<RexNode> |
retainDeterministic(java.util.List<RexNode> list) |
static java.lang.Iterable<RexNode> |
shift(java.lang.Iterable<RexNode> nodes,
int offset)
Shifts every
RexInputRef in an expression by offset . |
static RexNode |
shift(RexNode node,
int offset)
Shifts every
RexInputRef in an expression by offset . |
static RexNode |
shift(RexNode node,
int start,
int offset)
|
static RexNode |
simplify(RexBuilder rexBuilder,
RexNode e)
Deprecated.
Create a
RexSimplify , then call its
RexSimplify.simplify(RexNode, RexUnknownAs) method. |
static RexNode |
simplify(RexBuilder rexBuilder,
RexNode e,
boolean unknownAsFalse)
Deprecated.
Create a
RexSimplify , then call its
RexSimplify.simplify(RexNode, RexUnknownAs) method. |
static RexNode |
simplifyAnd(RexBuilder rexBuilder,
RexCall e,
boolean unknownAsFalse)
Deprecated.
|
static RexNode |
simplifyAnd2(RexBuilder rexBuilder,
java.util.List<RexNode> terms,
java.util.List<RexNode> notTerms)
Deprecated.
|
static RexNode |
simplifyAnd2ForUnknownAsFalse(RexBuilder rexBuilder,
java.util.List<RexNode> terms,
java.util.List<RexNode> notTerms)
Deprecated.
|
static RexNode |
simplifyAnds(RexBuilder rexBuilder,
java.lang.Iterable<? extends RexNode> nodes)
Deprecated.
|
static RexNode |
simplifyAnds(RexBuilder rexBuilder,
java.lang.Iterable<? extends RexNode> nodes,
boolean unknownAsFalse)
Deprecated.
|
static RexNode |
simplifyOr(RexBuilder rexBuilder,
RexCall call)
Deprecated.
|
static RexNode |
simplifyOrs(RexBuilder rexBuilder,
java.util.List<RexNode> terms)
Deprecated.
|
static RexNode |
simplifyPreservingType(RexBuilder rexBuilder,
RexNode e)
Deprecated.
Use
RexSimplify.simplifyPreservingType(RexNode) ,
which allows you to specify an RexExecutor . |
static java.util.List<java.lang.String> |
strings(java.util.List<RexNode> list)
Transforms a list of expressions to the list of digests.
|
static RexNode |
swapColumnReferences(RexBuilder rexBuilder,
RexNode node,
java.util.Map<RexTableInputRef,java.util.Set<RexTableInputRef>> ec)
Given an expression, it will swap its column references
RexTableInputRef
using the contents in the map (in particular, the first element of the set in the
map value). |
static RexNode |
swapColumnTableReferences(RexBuilder rexBuilder,
RexNode node,
java.util.Map<RexTableInputRef,java.util.Set<RexTableInputRef>> ec,
java.util.Map<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> tableMapping)
Given an expression, it will swap the column references
RexTableInputRef
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 its
RexTableInputRef using the contents in the second map. |
static RexNode |
swapTableColumnReferences(RexBuilder rexBuilder,
RexNode node,
java.util.Map<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> tableMapping,
java.util.Map<RexTableInputRef,java.util.Set<RexTableInputRef>> ec)
Given an expression, it will swap the table references contained in its
RexTableInputRef using the contents in the first map, and then
it will swap the column references RexTableInputRef using the contents
in the second map (in particular, the first element of the set in the map value). |
static RexNode |
swapTableReferences(RexBuilder rexBuilder,
RexNode node,
java.util.Map<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> tableMapping)
Given an expression, it will swap the table references contained in its
RexTableInputRef using the contents in the map. |
static RexNode |
toCnf(RexBuilder rexBuilder,
int maxCnfNodeCount,
RexNode rex)
Similar to
toCnf(RexBuilder, RexNode) ; however, it lets you
specify a threshold in the number of nodes that can be created out of
the conversion. |
static RexNode |
toCnf(RexBuilder rexBuilder,
RexNode rex)
Converts an expression to conjunctive normal form (CNF).
|
static RexNode |
toDnf(RexBuilder rexBuilder,
RexNode rex)
Converts an expression to disjunctive normal form (DNF).
|
static java.util.List<RelDataType> |
types(java.util.List<? extends RexNode> nodes)
Transforms a list of expressions into a list of their types.
|
public static final RexExecutor EXECUTOR
public static double getSelectivity(RexNode exp)
exp
- expression of interest, or null for none (implying a
selectivity of 1.0)public static java.util.List<RexNode> generateCastExpressions(RexBuilder rexBuilder, RelDataType lhsRowType, RelDataType rhsRowType)
rexBuilder
- RexBuilder to use for constructing castslhsRowType
- target row typerhsRowType
- source row type; fields must be 1-to-1 with lhsRowType,
in same orderpublic static java.util.List<RexNode> generateCastExpressions(RexBuilder rexBuilder, RelDataType lhsRowType, java.util.List<RexNode> rhsExps)
rexBuilder
- RexBuilder to use for constructing castslhsRowType
- target row typerhsExps
- expressions to be castpublic static boolean isNullLiteral(RexNode node, boolean allowCast)
Examples:
RexLiteral
Unknown, returns false.
CAST(NULL AS type)
, returns true if
allowCast
is true, false otherwise.
CAST(CAST(NULL AS type) AS type))
,
returns false.
public static boolean isNull(RexNode expr)
CAST(NULL AS type)
calls. For example:
isNull(CAST(CAST(NULL as INTEGER) AS VARCHAR(1)))
returns true
.public static boolean isLiteral(RexNode node, boolean allowCast)
Examples:
CAST(literal AS type)
, returns true if
allowCast
is true, false otherwise.
CAST(CAST(literal AS type) AS type))
,
returns false.
node
- The node, never null.allowCast
- whether to regard CAST(literal) as a literalpublic static boolean allLiterals(java.util.List<RexNode> expressionOperands)
expressionOperands
- list of expressions to checkpublic static boolean isReferenceOrAccess(RexNode node, boolean allowCast)
node
- The node, never null.allowCast
- whether to regard CAST(x) as truepublic static boolean isNullabilityCast(RelDataTypeFactory typeFactory, RexNode node)
public static RexNode removeNullabilityCast(RelDataTypeFactory typeFactory, RexNode node)
For example, CAST(1 = 0 AS BOOLEAN)
becomes 1 = 0
.
public static <C extends RexNode> com.google.common.collect.ImmutableMap<RexNode,C> predicateConstants(java.lang.Class<C> clazz, RexBuilder rexBuilder, java.util.List<RexNode> predicates)
C
- what to consider a constant: RexLiteral
to use a narrow
definition of constant, or RexNode
to use
isConstant(RexNode)
clazz
- Class of expression that is considered constantrexBuilder
- Rex builderpredicates
- Predicate listprivate static void decompose(java.util.Set<RexNode> set, RexNode rexNode)
private static <C extends RexNode> void gatherConstraints(java.lang.Class<C> clazz, RexNode predicate, java.util.Map<RexNode,C> map, java.util.Set<RexNode> excludeSet, RexBuilder rexBuilder)
private static <C extends RexNode> void gatherConstraint(java.lang.Class<C> clazz, RexNode left, RexNode right, java.util.Map<RexNode,C> map, java.util.Set<RexNode> excludeSet, RexBuilder rexBuilder)
private static boolean canAssignFrom(RelDataType type1, RelDataType type2)
type2
can be assigned to a variable
of type1
.
For example:
canAssignFrom(BIGINT, TINYINT)
returns true
canAssignFrom(TINYINT, BIGINT)
returns false
canAssignFrom(BIGINT, VARCHAR)
returns false
public static boolean isConstant(RexNode node)
node
- Node to inspectpublic static boolean isDeterministic(RexNode e)
e
- Expressionpublic static java.util.List<RexNode> retainDeterministic(java.util.List<RexNode> list)
public static RexCall findOperatorCall(SqlOperator operator, RexNode node)
operator
- Operator to look fornode
- a RexNode treepublic static boolean containsInputRef(RexNode node)
node
- a RexNode treepublic static boolean containsFieldAccess(RexNode node)
RexFieldAccess
nodes.node
- a RexNode treepublic static boolean requiresDecimalExpansion(RexNode expr, boolean recurse)
RexCall
requires decimal expansion. It
usually requires expansion if it has decimal operands.
Exceptions to this rule are:
expr
- expression possibly in need of expansionrecurse
- whether to check nested callspublic static boolean requiresDecimalExpansion(java.util.List<RexNode> operands, boolean recurse)
public static boolean requiresDecimalExpansion(RexProgram program, boolean recurse)
RexProgram
contains expressions which require
decimal expansion.public static boolean canReinterpretOverflow(RexCall call)
public static boolean containNoCommonExprs(java.util.List<RexNode> exprs, Litmus litmus)
public static boolean containNoForwardRefs(java.util.List<RexNode> exprs, RelDataType inputRowType, Litmus litmus)
RexInputRef
referencing
field i or greater.exprs
- Array of expressionsinputRowType
- Input row typelitmus
- What to do if an error is detected (there is a
forward reference)static boolean containNoNonTrivialAggs(java.util.List<RexNode> exprs, Litmus litmus)
RexInputRef
s.exprs
- Expressionslitmus
- Whether to assert if there is such a function callpublic static boolean containComplexExprs(java.util.List<RexNode> exprs)
RexVariable
(or a subtype such
as RexInputRef
) or RexLiteral
.public static boolean containsTableInputRef(java.util.List<RexNode> nodes)
nodes
- a list of RexNode treespublic static RexTableInputRef containsTableInputRef(RexNode node)
node
- a RexNode treepublic static boolean isAtomic(RexNode expr)
public static boolean isCallTo(RexNode expr, SqlOperator op)
public static RelDataType createStructType(RelDataTypeFactory typeFactory, java.util.List<RexNode> exprs)
typeFactory
- Type factoryexprs
- Expressionspublic static RelDataType createStructType(RelDataTypeFactory typeFactory, java.util.List<? extends RexNode> exprs, java.util.List<java.lang.String> names, SqlValidatorUtil.Suggester suggester)
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.
typeFactory
- Type factoryexprs
- Expressionsnames
- Field names, may be null, or elements may be nullsuggester
- Generates alternative names if names
is not
null and its elements are not unique@Deprecated public static RelDataType createStructType(RelDataTypeFactory typeFactory, java.util.List<? extends RexNode> exprs, java.util.List<java.lang.String> names)
public static boolean compatibleTypes(java.util.List<RexNode> exprs, RelDataType type, Litmus litmus)
exprs
- Array of expressionstype
- Typelitmus
- What to do if an error is detected (there is a mismatch)RelOptUtil.eq(String, RelDataType, String, RelDataType, org.apache.calcite.util.Litmus)
public static Pair<RexNode,java.lang.String> makeKey(RexNode expr)
RexNode
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.public static boolean containIdentity(java.util.List<? extends RexNode> exprs, RelDataType rowType, Litmus litmus)
RexInputRef
objects with types corresponding to the
underlying datatype.public static boolean isIdentity(java.util.List<? extends RexNode> exps, RelDataType inputRowType)
@Nonnull public static RexNode composeConjunction(RexBuilder rexBuilder, java.lang.Iterable<? extends RexNode> nodes)
composeConjunction(RexBuilder, Iterable, boolean)
but never
returns null.public static RexNode composeConjunction(RexBuilder rexBuilder, java.lang.Iterable<? extends RexNode> nodes, boolean nullOnEmpty)
nullOnEmpty
and expression is TRUE.public static com.google.common.collect.ImmutableList<RexNode> flattenAnd(java.lang.Iterable<? extends RexNode> nodes)
Treats null nodes as literal TRUE (i.e. ignores them).
private static void addAnd(com.google.common.collect.ImmutableList.Builder<RexNode> builder, java.util.Set<RexNode> digests, RexNode node)
@Nonnull public static RexNode composeDisjunction(RexBuilder rexBuilder, java.lang.Iterable<? extends RexNode> nodes)
public static RexNode composeDisjunction(RexBuilder rexBuilder, java.lang.Iterable<? extends RexNode> nodes, boolean nullOnEmpty)
public static com.google.common.collect.ImmutableList<RexNode> flattenOr(java.lang.Iterable<? extends RexNode> nodes)
private static void addOr(com.google.common.collect.ImmutableList.Builder<RexNode> builder, java.util.Set<RexNode> set, RexNode node)
public static java.util.List<RelCollation> apply(Mappings.TargetMapping mapping, java.util.List<RelCollation> collationList)
mapping
- MappingcollationList
- Collation listpublic static RelCollation apply(Mappings.TargetMapping mapping, RelCollation collation)
mapping
- Mappingcollation
- Collationpublic static RelFieldCollation apply(Mappings.TargetMapping mapping, RelFieldCollation fieldCollation)
If the field is not mapped, returns null.
mapping
- MappingfieldCollation
- Field collationpublic static java.util.List<RelFieldCollation> applyFields(Mappings.TargetMapping mapping, java.util.List<RelFieldCollation> fieldCollations)
mapping
- MappingfieldCollations
- Field collationspublic static RexNode apply(Mappings.TargetMapping mapping, RexNode node)
public static java.lang.Iterable<RexNode> apply(Mappings.TargetMapping mapping, java.lang.Iterable<? extends RexNode> nodes)
public static <T extends RexNode> T[] apply(RexVisitor<T> shuttle, T[] exprs)
shuttle
- Shuttleexprs
- Array of expressionspublic static void apply(RexVisitor<java.lang.Void> visitor, RexNode[] exprs, RexNode expr)
visitor
- Visitorexprs
- Array of expressionsexpr
- Single expression, may be nullpublic static void apply(RexVisitor<java.lang.Void> visitor, java.util.List<? extends RexNode> exprs, RexNode expr)
visitor
- Visitorexprs
- List of expressionsexpr
- Single expression, may be nullpublic static RexNode flatten(RexBuilder rexBuilder, RexNode node)
Returns the same expression if it is already flat.
public static java.util.List<RexNode> flatten(java.util.List<? extends RexNode> exprs, SqlOperator op)
private static boolean isFlat(java.util.List<? extends RexNode> exprs, SqlOperator op)
op
with exprs
as arguments
would be considered "flat".
For example, isFlat([w, AND[x, y], z, AND)
returns false;
isFlat([w, x, y, z], AND)
returns true.
public static boolean isFlat(RexNode expr)
private static void flattenRecurse(java.util.List<RexNode> list, java.util.List<? extends RexNode> exprs, SqlOperator op)
public static boolean isLosslessCast(RexNode node)
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.
public static RexNode toCnf(RexBuilder rexBuilder, RexNode rex)
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.
public static RexNode toCnf(RexBuilder rexBuilder, int maxCnfNodeCount, RexNode rex)
toCnf(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.
public static RexNode toDnf(RexBuilder rexBuilder, RexNode rex)
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.
private static boolean isAssociative(SqlOperator op)
public static <E> boolean exists(java.util.List<? extends E> list, Predicate1<E> predicate)
list
for which
predicate
is true.public static <E> boolean all(java.util.List<? extends E> list, Predicate1<E> predicate)
predicate
is true for all elements of
list
.public static RexNode shift(RexNode node, int offset)
RexInputRef
in an expression by offset
.public static java.lang.Iterable<RexNode> shift(java.lang.Iterable<RexNode> nodes, int offset)
RexInputRef
in an expression by offset
.public static RexNode pullFactors(RexBuilder rexBuilder, RexNode node)
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.
rexBuilder
- Rex buildernode
- Expression to transform@Deprecated public static java.util.List<RexNode> fixUp(RexBuilder rexBuilder, java.util.List<RexNode> nodes, RelDataType rowType)
public static java.util.List<RexNode> fixUp(RexBuilder rexBuilder, java.util.List<RexNode> nodes, java.util.List<RelDataType> fieldTypes)
RexInputRef
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.
public static java.util.List<RelDataType> types(java.util.List<? extends RexNode> nodes)
public static java.util.List<RelDataTypeFamily> families(java.util.List<RelDataType> types)
public static boolean removeAll(java.util.List<RexNode> targets, RexNode e)
@Deprecated public static boolean eq(RexNode e1, RexNode e2)
RexNode
s are structurally equal.
This method considers structure, not semantics. 'x < y' is not equivalent to 'y > x'.
@Deprecated public static RexNode simplifyPreservingType(RexBuilder rexBuilder, RexNode e)
RexSimplify.simplifyPreservingType(RexNode)
,
which allows you to specify an RexExecutor
.This is useful if you are simplifying expressions in a
Project
.
@Deprecated public static RexNode simplify(RexBuilder rexBuilder, RexNode e)
RexSimplify
, then call its
RexSimplify.simplify(RexNode, RexUnknownAs)
method.@Deprecated public static RexNode simplify(RexBuilder rexBuilder, RexNode e, boolean unknownAsFalse)
RexSimplify
, then call its
RexSimplify.simplify(RexNode, RexUnknownAs)
method.In particular:
simplify(x = 1 AND y = 2 AND NOT x = 1)
returns y = 2
simplify(x = 1 AND FALSE)
returns FALSE
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.
rexBuilder
- Rex buildere
- Expression to simplifyunknownAsFalse
- Whether to convert UNKNOWN values to FALSE@Deprecated public static RexNode simplifyAnds(RexBuilder rexBuilder, java.lang.Iterable<? extends RexNode> nodes)
RexSimplify.simplifyAnds(Iterable, RexUnknownAs)
.@Deprecated public static RexNode simplifyAnds(RexBuilder rexBuilder, java.lang.Iterable<? extends RexNode> nodes, boolean unknownAsFalse)
static SqlOperator op(SqlKind kind)
@Deprecated public static RexNode simplifyAnd(RexBuilder rexBuilder, RexCall e, boolean unknownAsFalse)
@Deprecated public static RexNode simplifyAnd2(RexBuilder rexBuilder, java.util.List<RexNode> terms, java.util.List<RexNode> notTerms)
@Deprecated public static RexNode simplifyAnd2ForUnknownAsFalse(RexBuilder rexBuilder, java.util.List<RexNode> terms, java.util.List<RexNode> notTerms)
public static RexNode negate(RexBuilder rexBuilder, RexCall call)
public static RexNode invert(RexBuilder rexBuilder, RexCall call)
@Deprecated public static RexNode simplifyOr(RexBuilder rexBuilder, RexCall call)
@Deprecated public static RexNode simplifyOrs(RexBuilder rexBuilder, java.util.List<RexNode> terms)
public static RexNode andNot(RexBuilder rexBuilder, RexNode e, RexNode... notTerms)
e1 AND NOT notTerm1 AND NOT notTerm2 ...
.@Nonnull public static RexNode andNot(RexBuilder rexBuilder, RexNode e, java.lang.Iterable<? extends RexNode> notTerms)
e1 AND NOT notTerm1 AND NOT notTerm2 ...
.
Examples:
public static boolean isCasePredicate(RexCall call, int i)
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.
private static boolean containsFalse(java.lang.Iterable<RexNode> nodes)
private static boolean containsTrue(java.lang.Iterable<RexNode> nodes)
@Deprecated public static com.google.common.base.Function<RexNode,RexNode> notFn(RexBuilder rexBuilder)
not(org.apache.calcite.rex.RexNode)
static RexNode not(RexBuilder rexBuilder, RexNode input)
public static boolean containsCorrelation(RexNode condition)
RexCorrelVariable
.public static RexNode swapTableReferences(RexBuilder rexBuilder, RexNode node, java.util.Map<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> tableMapping)
RexTableInputRef
using the contents in the map.public static RexNode swapColumnReferences(RexBuilder rexBuilder, RexNode node, java.util.Map<RexTableInputRef,java.util.Set<RexTableInputRef>> ec)
RexTableInputRef
using the contents in the map (in particular, the first element of the set in the
map value).public static RexNode swapTableColumnReferences(RexBuilder rexBuilder, RexNode node, java.util.Map<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> tableMapping, java.util.Map<RexTableInputRef,java.util.Set<RexTableInputRef>> ec)
RexTableInputRef
using the contents in the first map, and then
it will swap the column references RexTableInputRef
using the contents
in the second map (in particular, the first element of the set in the map value).public static RexNode swapColumnTableReferences(RexBuilder rexBuilder, RexNode node, java.util.Map<RexTableInputRef,java.util.Set<RexTableInputRef>> ec, java.util.Map<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> tableMapping)
RexTableInputRef
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 its
RexTableInputRef
using the contents in the second map.public static java.util.Set<RexTableInputRef.RelTableRef> gatherTableReferences(java.util.List<RexNode> nodes)
nodes
- expressionspublic static java.util.List<java.lang.String> strings(java.util.List<RexNode> list)
Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.