|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.rex.RexUtil
public class RexUtil
Utility methods concerning row-expressions.
Nested Class Summary | |
---|---|
private static class |
RexUtil.ExpressionNormalizer
Walks over expressions and builds a bank of common sub-expressions. |
static class |
RexUtil.FieldAccessFinder
Visitor which builds a bitmap of the inputs used by an expression. |
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) . |
Field Summary | |
---|---|
static RexNode[] |
emptyExpressionArray
|
Constructor Summary | |
---|---|
RexUtil()
|
Method Summary | |
---|---|
static RexNode |
andRexNodeList(RexBuilder rexBuilder,
List<RexNode> rexList)
Creates an AND expression from a list of RexNodes |
static boolean |
canReinterpretOverflow(RexCall call)
|
static RexNode[] |
clone(RexNode[] exps)
Returns a copy of an array of row-expressions. |
static RelDataType[] |
collectTypes(RexNode[] exprs)
Collects the types of an array of row expressions. |
static boolean |
compatibleTypes(RexNode[] exprs,
RelDataType type,
boolean fail)
Returns whether the type of an array of expressions is compatible with a struct type. |
static boolean |
containCommonExprs(RexNode[] exprs,
boolean fail)
Returns whether an array of expressions has any common sub-expressions. |
static boolean |
containComplexExprs(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 |
containForwardRefs(RexNode[] exprs,
RelDataType inputRowType,
boolean fail)
Returns whether an array of expressions contains a forward reference. |
static boolean |
containIdentity(RexNode[] exprs,
RelDataType rowType,
boolean fail)
Returns whether the leading edge of a given array of expressions is wholly RexInputRef objects with types corresponding to the
underlying datatype. |
(package private) static boolean |
containNonTrivialAggs(RexNode[] exprs,
boolean fail)
Returns whether an array of exp contains aggregate function calls whose arguments are not RexInputRef .s |
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 RexInputRef[] |
createIdentityArray(RexNode[] exprs)
Creates an array of RexInputRef objects referencing fields {0 .. |
static RelDataType |
createStructType(RelDataTypeFactory typeFactory,
RexNode[] exprs)
Creates a record type with anonymous field names. |
static RelDataType |
createStructType(RelDataTypeFactory typeFactory,
RexNode[] exprs,
String[] names)
Creates a record type with specified field names. |
static RexCall |
findOperatorCall(SqlOperator operator,
RexNode node)
Returns whether a given node contains a RexCall with a specified operator |
static RexNode[] |
generateCastExpressions(RexBuilder rexBuilder,
RelDataType lhsRowType,
RelDataType rhsRowType)
Generates a cast from one row type to another |
static RexNode[] |
generateCastExpressions(RexBuilder rexBuilder,
RelDataType lhsRowType,
RexNode[] rhsExps)
Generates a cast for a row type. |
static double |
getSelectivity(RexNode exp)
Returns a guess for the selectivity of an expression. |
static boolean |
isAtomic(RexNode expr)
|
static boolean |
isCallTo(RexNode expr,
SqlOperator op)
Returns whether a node is a call to a
given operator . |
static boolean |
isNull(RexNode node)
Returns whether a node represents the NULL value or a series of nested CAST(NULL as For Example: isNull(CAST(CAST(NULL as INTEGER) AS VARCHAR(1))) returns true |
static boolean |
isNullLiteral(RexNode node,
boolean allowCast)
Returns whether a node represents the NULL value. |
static 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 |
maybeCast(RexBuilder rexBuilder,
RelDataType lhsType,
RexNode expr)
Casts an expression to desired type, or returns the expression unchanged if it is already the correct type. |
static RexNode |
orRexNodeList(RexBuilder rexBuilder,
List<RexNode> rexList)
Creates an OR expression from a list of RexNodes |
static RexCall |
replaceOperands(RexCall call,
RexNode[] operands)
Replaces the operands of a call. |
static boolean |
requiresDecimalExpansion(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 RexInputRef[] |
toInputRefs(int[] args,
RelDataType rowType)
Creates an array of RexInputRef objects, one for each field of a
given rowtype, according to a permutation. |
static RexInputRef[] |
toInputRefs(RelDataType rowType)
Creates an array of RexInputRef , one for each field of a given
rowtype. |
static RexLocalRef[] |
toLocalRefs(RelDataType rowType)
Creates an array of RexLocalRef objects, one for each field of a
given rowtype. |
static Integer[] |
toOrdinalArray(RexNode[] rexNodes)
Converts an array of RexNode to an array of Integer . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final RexNode[] emptyExpressionArray
Constructor Detail |
---|
public RexUtil()
Method Detail |
---|
public static double getSelectivity(RexNode exp)
exp
- expression of interest, or null for none (implying a
selectivity of 1.0)
public static RexNode[] clone(RexNode[] exps)
public static 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 order
public static RexNode[] generateCastExpressions(RexBuilder rexBuilder, RelDataType lhsRowType, RexNode[] rhsExps)
rexBuilder
- RexBuilder to use for constructing castslhsRowType
- target row typerhsExps
- expressions to be cast
public static RexNode maybeCast(RexBuilder rexBuilder, RelDataType lhsType, RexNode expr)
rexBuilder
- Rex builderlhsType
- Desired typeexpr
- Expression
public 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 node)
public static RexCall findOperatorCall(SqlOperator operator, RexNode node)
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 RexInputRef[] toInputRefs(RelDataType rowType)
RexInputRef
, one for each field of a given
rowtype.
public static RexLocalRef[] toLocalRefs(RelDataType rowType)
RexLocalRef
objects, one for each field of a
given rowtype.
public static RexInputRef[] toInputRefs(int[] args, RelDataType rowType)
RexInputRef
objects, one for each field of a
given rowtype, according to a permutation.
args
- PermutationrowType
- Input row type
public static Integer[] toOrdinalArray(RexNode[] rexNodes)
RexNode
to an array of Integer
.
Every node must be a RexLocalRef
.
public static RelDataType[] collectTypes(RexNode[] exprs)
exprs
- array of row expressions
public 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 calls
public static boolean requiresDecimalExpansion(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 RexInputRef[] createIdentityArray(RexNode[] exprs)
RexInputRef
objects referencing fields {0 ..
N} and having types {exprs[0].getType() .. exprs[N].getType()}.
exprs
- Expressions whose types to mimic
public static boolean containCommonExprs(RexNode[] exprs, boolean fail)
public static boolean containForwardRefs(RexNode[] exprs, RelDataType inputRowType, boolean fail)
RexInputRef
referencing
field i or greater.
exprs
- Array of expressionsinputRowType
- fail
- Whether to assert if there is a forward reference
static boolean containNonTrivialAggs(RexNode[] exprs, boolean fail)
RexInputRef
.s
exprs
- Expressionsfail
- Whether to assert if there is such a function callpublic static boolean containComplexExprs(List<RexNode> exprs)
RexVariable
(or a subtype such
as RexInputRef
) or RexLiteral
.
public static RexCall replaceOperands(RexCall call, RexNode[] operands)
public static boolean isAtomic(RexNode expr)
public static boolean isCallTo(RexNode expr, SqlOperator op)
node
is a call
to a
given operator
.
public static RelDataType createStructType(RelDataTypeFactory typeFactory, RexNode[] exprs)
public static RelDataType createStructType(RelDataTypeFactory typeFactory, RexNode[] exprs, String[] 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.
public static boolean compatibleTypes(RexNode[] exprs, RelDataType type, boolean fail)
exprs
- Array of expressionstype
- Typefail
- Whether to fail if there is a mismatch
RelOptUtil.eq(String, RelDataType, String, RelDataType, boolean)
public static 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(RexNode[] exprs, RelDataType rowType, boolean fail)
RexInputRef
objects with types corresponding to the
underlying datatype.
public static RexNode andRexNodeList(RexBuilder rexBuilder, List<RexNode> rexList)
rexList
- list of RexNodes
public static RexNode orRexNodeList(RexBuilder rexBuilder, List<RexNode> rexList)
rexList
- list of RexNodes
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |