public class RexBuilder extends Object
Some common literal values (NULL, TRUE, FALSE, 0, 1, '') are cached.
| Modifier and Type | Field and Description |
|---|---|
static SqlSpecialOperator |
GET_OPERATOR
Special operator that accesses an unadvertised field of an input record.
|
static com.google.common.base.Function<RelDataTypeField,RexInputRef> |
TO_INPUT_REF |
protected RelDataTypeFactory |
typeFactory |
| Constructor and Description |
|---|
RexBuilder(RelDataTypeFactory typeFactory)
Creates a RexBuilder.
|
| Modifier and Type | Method and Description |
|---|---|
RexNode |
addAggCall(AggregateCall aggCall,
int groupCount,
boolean indicator,
List<AggregateCall> aggCalls,
Map<AggregateCall,RexNode> aggCallMapping,
List<RelDataType> aggArgTypes)
Creates a reference to an aggregate call, checking for repeated calls.
|
RexLiteral |
constantNull()
Creates a constant for the SQL
NULL value. |
RexNode |
copy(RexNode expr)
Creates a copy of an expression, which may have been created using a
different RexBuilder and/or
RelDataTypeFactory, using this
RexBuilder. |
RexNode |
decodeIntervalOrDecimal(RexNode node)
Retrieves an interval or decimal node's integer representation
|
RelDataType |
deriveReturnType(SqlOperator op,
List<? extends RexNode> exprs)
Derives the return type of a call to an operator.
|
RexNode |
encodeIntervalOrDecimal(RexNode value,
RelDataType type,
boolean checkOverflow)
Casts a decimal's integer representation to a decimal node.
|
RexNode |
ensureType(RelDataType type,
RexNode node,
boolean matchNullability)
Ensures expression is interpreted as a specified type.
|
SqlStdOperatorTable |
getOpTab()
Returns this RexBuilder's operator table
|
RelDataTypeFactory |
getTypeFactory()
Returns this RexBuilder's type factory
|
List<RexInputRef> |
identityProjects(RelDataType rowType)
Creates a list of
RexInputRef expressions,
projecting the fields of a given record type. |
RexNode |
makeAbstractCast(RelDataType type,
RexNode exp)
Creates a call to the CAST operator.
|
RexLiteral |
makeApproxLiteral(BigDecimal bd)
Creates a double-precision literal.
|
RexLiteral |
makeApproxLiteral(BigDecimal bd,
RelDataType type)
Creates an approximate numeric literal (double or float).
|
RexLiteral |
makeBigintLiteral(BigDecimal bd)
Creates a BIGINT literal.
|
RexLiteral |
makeBinaryLiteral(ByteString byteString)
Creates a byte array literal.
|
RexNode |
makeCall(RelDataType returnType,
SqlOperator op,
List<RexNode> exprs)
Creates a call with a list of arguments and a predetermined type.
|
RexNode |
makeCall(SqlOperator op,
List<? extends RexNode> exprs)
Creates a call with an array of arguments.
|
RexNode |
makeCall(SqlOperator op,
RexNode... exprs)
Creates a call with a list of arguments.
|
RexNode |
makeCast(RelDataType type,
RexNode exp)
Creates a call to the CAST operator, expanding if possible.
|
RexLiteral |
makeCharLiteral(NlsString str)
Creates a character string literal from an
NlsString. |
RexNode |
makeCorrel(RelDataType type,
String name)
Creates an expression referencing a correlation variable.
|
RexLiteral |
makeDateLiteral(Calendar date)
Creates a Date literal.
|
RexDynamicParam |
makeDynamicParam(RelDataType type,
int index)
Creates a reference to a dynamic parameter
|
RexLiteral |
makeExactLiteral(BigDecimal bd)
Creates a numeric literal.
|
RexLiteral |
makeExactLiteral(BigDecimal bd,
RelDataType type)
Creates a numeric literal.
|
RexNode |
makeFieldAccess(RexNode expr,
int i)
Creates an expression accessing a field with a given ordinal from a
record.
|
RexNode |
makeFieldAccess(RexNode expr,
String fieldName,
boolean caseSensitive)
Creates an expression accessing a given named field from a record.
|
RexLiteral |
makeFlag(Enum flag)
Creates a literal representing a flag.
|
RexInputRef |
makeInputRef(RelDataType type,
int i)
Creates a reference to a given field of the input record.
|
RexInputRef |
makeInputRef(RelNode input,
int i)
Creates a reference to a given field of the input relational expression.
|
RexLiteral |
makeIntervalLiteral(BigDecimal v,
SqlIntervalQualifier intervalQualifier)
Creates an interval literal.
|
RexLiteral |
makeIntervalLiteral(SqlIntervalQualifier intervalQualifier)
Creates an interval literal.
|
RexLiteral |
makeLiteral(boolean b)
Creates a boolean literal.
|
protected RexLiteral |
makeLiteral(Comparable o,
RelDataType type,
SqlTypeName typeName)
Internal method to create a call to a literal.
|
RexNode |
makeLiteral(Object value,
RelDataType type,
boolean allowCast)
Creates a literal of a given type.
|
RexLiteral |
makeLiteral(String s)
Creates a character string literal.
|
RexNode |
makeNewInvocation(RelDataType type,
List<RexNode> exprs)
Creates an invocation of the NEW operator.
|
RexNode |
makeNotNullCast(RexNode expr)
Makes an expression which converts a value of type T to a value of type T
NOT NULL, or throws if the value is NULL.
|
RexNode |
makeNullLiteral(SqlTypeName typeName)
Creates a literal whose value is NULL, with a particular type.
|
RexNode |
makeNullLiteral(SqlTypeName typeName,
int precision)
Creates an expression corresponding to a null literal, cast to a specific
type and precision
|
RexNode |
makeOver(RelDataType type,
SqlAggFunction operator,
List<RexNode> exprs,
List<RexNode> partitionKeys,
com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys,
RexWindowBound lowerBound,
RexWindowBound upperBound,
boolean physical,
boolean allowPartial,
boolean nullWhenCountZero)
Creates a call to a windowed agg.
|
protected RexLiteral |
makePreciseStringLiteral(String s)
Creates a character string literal with type CHAR and default charset and
collation.
|
RexRangeRef |
makeRangeReference(RelDataType type,
int offset,
boolean nullable)
Creates a reference to all the fields in the row.
|
RexNode |
makeRangeReference(RelNode input)
Creates a reference to all the fields in the row.
|
RexNode |
makeReinterpretCast(RelDataType type,
RexNode exp,
RexNode checkOverflow)
Makes a reinterpret cast.
|
RexLiteral |
makeTimeLiteral(Calendar time,
int precision)
Creates a Time literal.
|
RexLiteral |
makeTimestampLiteral(Calendar timestamp,
int precision)
Creates a Timestamp literal.
|
RexWindow |
makeWindow(List<RexNode> partitionKeys,
com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys,
RexWindowBound lowerBound,
RexWindowBound upperBound,
boolean isRows)
Creates a window specification.
|
RexNode |
makeZeroLiteral(RelDataType type)
Creates a literal of the default value for the given type.
|
RelDataType |
matchNullability(RelDataType type,
RexNode value)
Ensures that a type's nullability matches a value's nullability.
|
public static final SqlSpecialOperator GET_OPERATOR
public static final com.google.common.base.Function<RelDataTypeField,RexInputRef> TO_INPUT_REF
protected final RelDataTypeFactory typeFactory
public RexBuilder(RelDataTypeFactory typeFactory)
typeFactory - Type factorypublic List<RexInputRef> identityProjects(RelDataType rowType)
RexInputRef expressions,
projecting the fields of a given record type.public RelDataTypeFactory getTypeFactory()
public SqlStdOperatorTable getOpTab()
public RexNode makeFieldAccess(RexNode expr, String fieldName, boolean caseSensitive)
NOTE: Be careful choosing the value of caseSensitive.
If the field name was supplied by an end-user (e.g. as a column alias in
SQL), use your session's case-sensitivity setting.
Only hard-code true if you are sure that the field name is
internally generated.
Hard-coding false is almost certainly wrong.
expr - Expression yielding a recordfieldName - Name of field in recordcaseSensitive - Whether match is case-sensitivepublic RexNode makeFieldAccess(RexNode expr, int i)
expr - Expression yielding a recordi - Ordinal of fieldpublic RexNode makeCall(RelDataType returnType, SqlOperator op, List<RexNode> exprs)
public RexNode makeCall(SqlOperator op, List<? extends RexNode> exprs)
If you already know the return type of the call, then
makeCall(org.apache.calcite.rel.type.RelDataType, org.apache.calcite.sql.SqlOperator, java.util.List)
is preferred.
public final RexNode makeCall(SqlOperator op, RexNode... exprs)
Equivalent to
makeCall(op, exprList.toArray(new RexNode[exprList.size()])).
public RelDataType deriveReturnType(SqlOperator op, List<? extends RexNode> exprs)
op - the operator being calledexprs - actual operandspublic RexNode addAggCall(AggregateCall aggCall, int groupCount, boolean indicator, List<AggregateCall> aggCalls, Map<AggregateCall,RexNode> aggCallMapping, List<RelDataType> aggArgTypes)
Argument types help to optimize for repeated aggregates. For instance count(42) is equivalent to count(*).
aggCall - aggregate call to be addedgroupCount - number of groups in the aggregate relationindicator - Whether the Aggregate has indicator (GROUPING) columnsaggCalls - destination list of aggregate callsaggCallMapping - the dictionary of already added callsaggArgTypes - Argument types, not nullpublic RexNode makeOver(RelDataType type, SqlAggFunction operator, List<RexNode> exprs, List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean physical, boolean allowPartial, boolean nullWhenCountZero)
public RexWindow makeWindow(List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean isRows)
partitionKeys - Partition keysorderKeys - Order keyslowerBound - Lower boundupperBound - Upper boundisRows - Whether physical. True if row-based, false if
range-basedpublic RexLiteral constantNull()
NULL value.public RexNode makeCorrel(RelDataType type, String name)
type - Type of variablename - Name of variablepublic RexNode makeNewInvocation(RelDataType type, List<RexNode> exprs)
type - Type to be instantiatedexprs - Arguments to NEW operatorpublic RexNode makeCast(RelDataType type, RexNode exp)
type - Type to cast toexp - Expression being castpublic RexNode encodeIntervalOrDecimal(RexNode value, RelDataType type, boolean checkOverflow)
An overflow check may be requested to ensure the internal value does not exceed the maximum value of the decimal type.
value - integer representation of decimaltype - type integer will be reinterpreted ascheckOverflow - indicates whether an overflow check is required
when reinterpreting this particular value as the
decimal type. A check usually not required for
arithmetic, but is often required for rounding and
explicit casts.public RexNode decodeIntervalOrDecimal(RexNode node)
node - the interval or decimal value as an opaque typepublic RexNode makeAbstractCast(RelDataType type, RexNode exp)
type - Type to cast toexp - Expression being castpublic RexNode makeReinterpretCast(RelDataType type, RexNode exp, RexNode checkOverflow)
type - type returned by the castexp - expression to be castedcheckOverflow - whether an overflow check is requiredpublic RexNode makeNotNullCast(RexNode expr)
public RexNode makeRangeReference(RelNode input)
input - Input relational expressionpublic RexRangeRef makeRangeReference(RelDataType type, int offset, boolean nullable)
For example, if the input row has type T{f0,f1,f2,f3,f4}
then makeRangeReference(T{f0,f1,f2,f3,f4}, S{f3,f4}, 3) is
an expression which yields the last 2 fields.
type - Type of the resulting range record.offset - Index of first field.nullable - Whether the record is nullable.public RexInputRef makeInputRef(RelDataType type, int i)
type - Type of fieldi - Ordinal of fieldpublic RexInputRef makeInputRef(RelNode input, int i)
input - Input relational expressioni - Ordinal of fieldpublic RexLiteral makeFlag(Enum flag)
flag - Flag valueprotected RexLiteral makeLiteral(Comparable o, RelDataType type, SqlTypeName typeName)
makeDateLiteral(Calendar), makeLiteral(boolean),
makeLiteral(String).o - Value of literal, must be appropriate for the typetype - Type of literaltypeName - SQL type of literalpublic RexLiteral makeLiteral(boolean b)
public RexLiteral makeExactLiteral(BigDecimal bd)
public RexLiteral makeBigintLiteral(BigDecimal bd)
public RexLiteral makeExactLiteral(BigDecimal bd, RelDataType type)
public RexLiteral makeBinaryLiteral(ByteString byteString)
public RexLiteral makeApproxLiteral(BigDecimal bd)
public RexLiteral makeApproxLiteral(BigDecimal bd, RelDataType type)
bd - literal valuetype - approximate numeric typepublic RexLiteral makeLiteral(String s)
protected RexLiteral makePreciseStringLiteral(String s)
s - String valuepublic RexNode ensureType(RelDataType type, RexNode node, boolean matchNullability)
type - desired typenode - expressionmatchNullability - whether to correct nullability of specified
type to match the expression; this usually should
be true, except for explicit casts which can
override default nullabilitypublic RelDataType matchNullability(RelDataType type, RexNode value)
public RexLiteral makeCharLiteral(NlsString str)
NlsString.
If the string's charset and collation are not set, uses the system defaults.
public RexLiteral makeDateLiteral(Calendar date)
public RexLiteral makeTimeLiteral(Calendar time, int precision)
public RexLiteral makeTimestampLiteral(Calendar timestamp, int precision)
public RexLiteral makeIntervalLiteral(SqlIntervalQualifier intervalQualifier)
public RexLiteral makeIntervalLiteral(BigDecimal v, SqlIntervalQualifier intervalQualifier)
public RexDynamicParam makeDynamicParam(RelDataType type, int index)
type - Type of dynamic parameterindex - Index of dynamic parameterpublic RexNode makeNullLiteral(SqlTypeName typeName, int precision)
typeName - name of the type that the null will be cast toprecision - precision of the typepublic RexNode makeNullLiteral(SqlTypeName typeName)
The typing is necessary because RexNodes are strictly typed. For
example, in the Rex world the NULL parameter to
SUBSTRING(NULL FROM 2 FOR 4) must have a valid VARCHAR type so
that the result type can be determined.
typeName - Type to cast NULL topublic RexNode copy(RexNode expr)
RelDataTypeFactory, using this
RexBuilder.expr - ExpressionRelDataTypeFactory.copyType(RelDataType)public RexNode makeZeroLiteral(RelDataType type)
This value is:
type - Typepublic RexNode makeLiteral(Object value, RelDataType type, boolean allowCast)
value - Valuetype - TypeallowCast - Whether to allow a cast. If false, value is always a
RexLiteral but may not be the exact typeCopyright © 2012–2015 The Apache Software Foundation. All rights reserved.