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.
|
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,
@Nullable List<RelDataType> aggArgTypes)
Deprecated.
|
RexNode |
addAggCall(AggregateCall aggCall,
int groupCount,
List<AggregateCall> aggCalls,
Map<AggregateCall,RexNode> aggCallMapping,
IntPredicate isNullable)
Creates a reference to an aggregate call, checking for repeated calls.
|
RexNode |
addAggCall(AggregateCall aggCall,
int groupCount,
List<AggregateCall> aggCalls,
Map<AggregateCall,RexNode> aggCallMapping,
@Nullable List<RelDataType> aggArgTypes)
Deprecated.
|
protected static org.apache.calcite.avatica.util.TimeUnit |
baseUnit(SqlTypeName unit)
Returns the lowest granularity unit for the given unit.
|
RexLiteral |
constantNull()
Deprecated.
Use
makeNullLiteral(RelDataType), which produces a
NULL of the correct type |
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<RexNode> |
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(@Nullable BigDecimal bd,
RelDataType type)
Creates an approximate numeric literal (double or float).
|
RexNode |
makeBetween(RexNode arg,
RexNode lower,
RexNode upper)
Creates a
RexNode representation a SQL
"arg BETWEEN lower AND upper" expression. |
RexLiteral |
makeBigintLiteral(@Nullable BigDecimal bd)
Creates a BIGINT literal.
|
RexLiteral |
makeBinaryLiteral(org.apache.calcite.avatica.util.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.
|
RexNode |
makeCast(RelDataType type,
RexNode exp,
boolean matchNullability)
Creates a call to the CAST operator, expanding if possible, and optionally
also preserving nullability.
|
RexLiteral |
makeCharLiteral(NlsString str)
Creates a character string literal from an
NlsString. |
RexNode |
makeCorrel(RelDataType type,
CorrelationId id)
Creates an expression referencing a correlation variable.
|
RexLiteral |
makeDateLiteral(Calendar calendar)
Deprecated.
|
RexLiteral |
makeDateLiteral(DateString 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(@Nullable 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.
|
RexNode |
makeIn(RexNode arg,
List<? extends RexNode> ranges)
Creates a
RexNode representation a SQL "arg IN (point, ...)"
expression. |
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(@Nullable BigDecimal v,
SqlIntervalQualifier intervalQualifier)
Creates a literal representing an interval value, for example
INTERVAL '3-7' YEAR TO MONTH. |
RexLiteral |
makeIntervalLiteral(SqlIntervalQualifier intervalQualifier)
Creates a literal representing an interval type, for example
YEAR TO MONTH or DOW. |
RexLiteral |
makeLiteral(boolean b)
Creates a boolean literal.
|
protected RexLiteral |
makeLiteral(@Nullable Comparable o,
RelDataType type,
SqlTypeName typeName)
Internal method to create a call to a literal.
|
RexLiteral |
makeLiteral(@Nullable Object value,
RelDataType type)
Creates a literal of a given type, padding values of constant-width
types to match their type, not allowing casts.
|
RexNode |
makeLiteral(@Nullable Object value,
RelDataType type,
boolean allowCast)
Creates a literal of a given type, padding values of constant-width
types to match their type.
|
RexNode |
makeLiteral(@Nullable Object value,
RelDataType type,
boolean allowCast,
boolean trim)
Creates a literal of a given type.
|
RexLiteral |
makeLiteral(String s)
Creates a character string literal.
|
RexLocalRef |
makeLocalRef(RelDataType type,
int i)
Create a reference to local variable.
|
RexNode |
makeNewInvocation(RelDataType type,
List<RexNode> exprs)
Creates an invocation of the NEW operator.
|
RexNode |
makeNotNull(RexNode exp)
Makes a cast of a value to NOT NULL;
no-op if the type already has NOT NULL.
|
RexLiteral |
makeNullLiteral(RelDataType type)
Creates a literal whose value is NULL, with a particular type.
|
RexNode |
makeNullLiteral(SqlTypeName typeName)
Deprecated.
|
RexNode |
makeNullLiteral(SqlTypeName typeName,
int precision)
Deprecated.
|
RexNode |
makeOver(RelDataType type,
SqlAggFunction operator,
List<RexNode> exprs,
List<RexNode> partitionKeys,
com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys,
RexWindowBound lowerBound,
RexWindowBound upperBound,
boolean rows,
boolean allowPartial,
boolean nullWhenCountZero,
boolean distinct)
Deprecated.
|
RexNode |
makeOver(RelDataType type,
SqlAggFunction operator,
List<RexNode> exprs,
List<RexNode> partitionKeys,
com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys,
RexWindowBound lowerBound,
RexWindowBound upperBound,
boolean rows,
boolean allowPartial,
boolean nullWhenCountZero,
boolean distinct,
boolean ignoreNulls)
Creates a call to a windowed agg.
|
RexPatternFieldRef |
makePatternFieldRef(String alpha,
RelDataType type,
int i)
Creates a reference to a given field of the pattern.
|
protected RexLiteral |
makePreciseStringLiteral(org.apache.calcite.avatica.util.ByteString value,
String charsetName,
SqlCollation collation)
Creates a character string literal with type CHAR.
|
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 |
makeSearchArgumentLiteral(Sarg s,
RelDataType type)
Creates a search argument literal.
|
RexLiteral |
makeTimeLiteral(Calendar calendar,
int precision)
Deprecated.
|
RexLiteral |
makeTimeLiteral(TimeString time,
int precision)
Creates a Time literal.
|
RexLiteral |
makeTimestampLiteral(Calendar calendar,
int precision)
Deprecated.
|
RexLiteral |
makeTimestampLiteral(TimestampString timestamp,
int precision)
Creates a Timestamp literal.
|
RexLiteral |
makeTimestampWithLocalTimeZoneLiteral(TimestampString timestamp,
int precision)
Creates a Timestamp with local time-zone literal.
|
RexLiteral |
makeTimeWithLocalTimeZoneLiteral(TimeString time,
int precision)
Creates a Time with local time-zone literal.
|
RexWindow |
makeWindow(List<RexNode> partitionKeys,
com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys,
RexWindowBound lowerBound,
RexWindowBound upperBound,
boolean rows)
Creates a window specification.
|
RexLiteral |
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.
|
RexNode |
multiplyDivide(RexNode e,
BigDecimal multiplier,
BigDecimal divider) |
public static final SqlSpecialOperator GET_OPERATOR
protected final RelDataTypeFactory typeFactory
public RexBuilder(RelDataTypeFactory typeFactory)
typeFactory - Type factorypublic List<RexNode> 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, List<AggregateCall> aggCalls, Map<AggregateCall,RexNode> aggCallMapping, IntPredicate isNullable)
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 relationaggCalls - destination list of aggregate callsaggCallMapping - the dictionary of already added callsisNullable - Whether input field i is nullable@Deprecated public RexNode addAggCall(AggregateCall aggCall, int groupCount, List<AggregateCall> aggCalls, Map<AggregateCall,RexNode> aggCallMapping, @Nullable List<RelDataType> aggArgTypes)
@Deprecated public RexNode addAggCall(AggregateCall aggCall, int groupCount, boolean indicator, List<AggregateCall> aggCalls, Map<AggregateCall,RexNode> aggCallMapping, @Nullable List<RelDataType> aggArgTypes)
@Deprecated public RexNode makeOver(RelDataType type, SqlAggFunction operator, List<RexNode> exprs, List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean rows, boolean allowPartial, boolean nullWhenCountZero, boolean distinct)
public RexNode makeOver(RelDataType type, SqlAggFunction operator, List<RexNode> exprs, List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean rows, boolean allowPartial, boolean nullWhenCountZero, boolean distinct, boolean ignoreNulls)
public RexWindow makeWindow(List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean rows)
partitionKeys - Partition keysorderKeys - Order keyslowerBound - Lower boundupperBound - Upper boundrows - Whether physical. True if row-based, false if
range-based@Deprecated public RexLiteral constantNull()
makeNullLiteral(RelDataType), which produces a
NULL of the correct typeNULL value.public RexNode makeCorrel(RelDataType type, CorrelationId id)
id - Name of variabletype - Type 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 makeCast(RelDataType type, RexNode exp, boolean matchNullability)
Tries to expand the cast, and therefore the result may be something
other than a RexCall to the CAST operator, such as a
RexLiteral.
type - Type to cast toexp - Expression being castmatchNullability - Whether to ensure the result has the same
nullability as typeprotected static org.apache.calcite.avatica.util.TimeUnit baseUnit(SqlTypeName unit)
public RexNode multiplyDivide(RexNode e, BigDecimal multiplier, BigDecimal divider)
public 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 makeNotNull(RexNode exp)
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 fieldidentityProjects(RelDataType)public RexPatternFieldRef makePatternFieldRef(String alpha, RelDataType type, int i)
alpha - the pattern nametype - Type of fieldi - Ordinal of fieldpublic RexLocalRef makeLocalRef(RelDataType type, int i)
type - Type of variablei - Ordinal of variablepublic RexLiteral makeFlag(Enum flag)
flag - Flag valueprotected RexLiteral makeLiteral(@Nullable Comparable o, RelDataType type, SqlTypeName typeName)
makeDateLiteral(DateString), 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(@Nullable BigDecimal bd)
public RexLiteral makeExactLiteral(@Nullable BigDecimal bd, RelDataType type)
public RexLiteral makeBinaryLiteral(org.apache.calcite.avatica.util.ByteString byteString)
public RexLiteral makeApproxLiteral(BigDecimal bd)
public RexLiteral makeApproxLiteral(@Nullable BigDecimal bd, RelDataType type)
bd - literal valuetype - approximate numeric typepublic RexLiteral makeSearchArgumentLiteral(Sarg s, RelDataType type)
public RexLiteral makeLiteral(String s)
protected RexLiteral makePreciseStringLiteral(String s)
s - String valueprotected RexLiteral makePreciseStringLiteral(org.apache.calcite.avatica.util.ByteString value, String charsetName, SqlCollation collation)
value - String value in bytescharsetName - SQL-level charset namecollation - Sql collationpublic 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.
@Deprecated public RexLiteral makeDateLiteral(Calendar calendar)
makeDateLiteral(DateString).public RexLiteral makeDateLiteral(DateString date)
@Deprecated public RexLiteral makeTimeLiteral(Calendar calendar, int precision)
makeTimeLiteral(TimeString, int).public RexLiteral makeTimeLiteral(TimeString time, int precision)
public RexLiteral makeTimeWithLocalTimeZoneLiteral(TimeString time, int precision)
@Deprecated public RexLiteral makeTimestampLiteral(Calendar calendar, int precision)
makeTimestampLiteral(TimestampString, int).public RexLiteral makeTimestampLiteral(TimestampString timestamp, int precision)
public RexLiteral makeTimestampWithLocalTimeZoneLiteral(TimestampString timestamp, int precision)
public RexLiteral makeIntervalLiteral(SqlIntervalQualifier intervalQualifier)
YEAR TO MONTH or DOW.public RexLiteral makeIntervalLiteral(@Nullable BigDecimal v, SqlIntervalQualifier intervalQualifier)
INTERVAL '3-7' YEAR TO MONTH.public RexDynamicParam makeDynamicParam(RelDataType type, int index)
type - Type of dynamic parameterindex - Index of dynamic parameterpublic RexLiteral makeNullLiteral(RelDataType type)
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.
type - Type to cast NULL to@Deprecated public RexNode makeNullLiteral(SqlTypeName typeName, int precision)
makeNullLiteral(RelDataType)@Deprecated public RexNode makeNullLiteral(SqlTypeName typeName)
makeNullLiteral(RelDataType)public RexNode copy(RexNode expr)
RelDataTypeFactory, using this
RexBuilder.expr - ExpressionRelDataTypeFactory.copyType(RelDataType)public RexLiteral makeZeroLiteral(RelDataType type)
This value is:
type - Typepublic RexLiteral makeLiteral(@Nullable Object value, RelDataType type)
value - Valuetype - Typepublic RexNode makeLiteral(@Nullable 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 typepublic RexNode makeLiteral(@Nullable Object value, RelDataType type, boolean allowCast, boolean trim)
The trim parameter controls whether to trim values of
constant-width types such as CHAR. Consider a call to
makeLiteral("foo ", CHAR(5), and note that the value is too short
for its type. If trim is true, the value is converted to "foo"
and the type to CHAR(3); if trim is false, the value is
right-padded with spaces to "foo ", to match the type
CHAR(5).
value - Valuetype - TypeallowCast - Whether to allow a cast. If false, value is always a
RexLiteral but may not be the exact typetrim - Whether to trim values and type to the shortest equivalent
value; for example whether to convert CHAR(4) 'foo '
to CHAR(3) 'foo'Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.