Class RexBuilder
Some common literal values (NULL, TRUE, FALSE, 0, 1, '') are cached.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final SqlSpecialOperator
Special operator that accesses an unadvertised field of an input record.protected final RelDataTypeFactory
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAggCall
(AggregateCall aggCall, int groupCount, boolean indicator, List<AggregateCall> aggCalls, Map<AggregateCall, RexNode> aggCallMapping, @Nullable List<RelDataType> aggArgTypes) Deprecated.addAggCall
(AggregateCall aggCall, int groupCount, List<AggregateCall> aggCalls, Map<AggregateCall, RexNode> aggCallMapping, @Nullable List<RelDataType> aggArgTypes) Deprecated.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.protected static org.apache.calcite.avatica.util.TimeUnit
baseUnit
(SqlTypeName unit) Returns the lowest granularity unit for the given unit.Deprecated.Creates a copy of an expression, which may have been created using a different RexBuilder and/orRelDataTypeFactory
, using this RexBuilder.Retrieves an INTERVAL or DECIMAL node's integer representation.decodeIntervalOrDecimal
(SqlParserPos pos, RexNode node) deriveReturnType
(SqlOperator op, List<? extends RexNode> exprs) Derives the return type of a call to an operator.encodeIntervalOrDecimal
(RexNode value, RelDataType type, boolean checkOverflow) Casts a decimal's integer representation to a decimal node.encodeIntervalOrDecimal
(SqlParserPos pos, RexNode value, RelDataType type, boolean checkOverflow) ensureType
(RelDataType type, RexNode node, boolean matchNullability) Ensures expression is interpreted as a specified type.ensureType
(SqlParserPos pos, RelDataType type, RexNode node, boolean matchNullability) Ensures expression is interpreted as a specified type.getOpTab()
Returns this RexBuilder's operator table.Returns this RexBuilder's type factory.identityProjects
(RelDataType rowType) Creates a list ofRexInputRef
expressions, projecting the fields of a given record type.makeAbstractCast
(RelDataType type, RexNode exp) Deprecated.makeAbstractCast
(RelDataType type, RexNode exp, boolean safe) Creates a call to CAST or SAFE_CAST operator.makeAbstractCast
(RelDataType type, RexNode exp, boolean safe, RexLiteral format) Creates a call to CAST or SAFE_CAST operator with a FORMAT clause.makeAbstractCast
(SqlParserPos pos, RelDataType type, RexNode exp, boolean safe) Creates a call to CAST or SAFE_CAST operator.makeAbstractCast
(SqlParserPos pos, RelDataType type, RexNode exp, boolean safe, RexLiteral format) Creates a call to CAST or SAFE_CAST operator with a FORMAT clause.makeApproxLiteral
(Double val, RelDataType type) Creates an approximate numeric literal (double or float) from a Double value.makeApproxLiteral
(@Nullable BigDecimal bd, RelDataType type) Creates an approximate numeric literal (double or float).Creates a double-precision literal.makeBetween
(RexNode arg, RexNode lower, RexNode upper) Creates aRexNode
representation a SQL "arg BETWEEN lower AND upper" expression.makeBigintLiteral
(@Nullable BigDecimal bd) Creates a BIGINT literal.makeBinaryLiteral
(org.apache.calcite.avatica.util.ByteString byteString) Creates a byte array literal.makeCall
(RelDataType returnType, SqlOperator op, List<RexNode> exprs) Creates a call with a list of arguments and a predetermined type.makeCall
(SqlParserPos pos, RelDataType returnType, SqlOperator op, List<RexNode> exprs) Creates a call with a list of arguments and a predetermined type.makeCall
(SqlParserPos pos, SqlOperator op, List<? extends RexNode> exprs) Creates a call with an array of arguments.final RexNode
makeCall
(SqlParserPos pos, SqlOperator op, RexNode... exprs) Creates a call with a list of arguments.makeCall
(SqlOperator op, List<? extends RexNode> exprs) Creates a call with an array of arguments.final RexNode
makeCall
(SqlOperator op, RexNode... exprs) Creates a call with a list of arguments.makeCast
(RelDataType type, RexNode exp) Creates a call to the CAST operator.makeCast
(RelDataType type, RexNode exp, boolean matchNullability) Deprecated.makeCast
(RelDataType type, RexNode exp, boolean matchNullability, boolean safe) Creates a call to the CAST operator, expanding if possible, and optionally also preserving nullability, and optionally in safe mode.makeCast
(RelDataType type, RexNode exp, boolean matchNullability, boolean safe, RexLiteral format) Creates a call to the CAST operator, expanding if possible, and optionally also preserving nullability, and optionally in safe mode.makeCast
(SqlParserPos pos, RelDataType type, RexNode exp) Creates a call to the CAST operator.makeCast
(SqlParserPos pos, RelDataType type, RexNode exp, boolean matchNullability, boolean safe) Creates a call to the CAST operator, expanding if possible, and optionally also preserving nullability, and optionally in safe mode.makeCast
(SqlParserPos pos, RelDataType type, RexNode exp, boolean matchNullability, boolean safe, RexLiteral format) Creates a call to the CAST operator, expanding if possible, and optionally also preserving nullability, and optionally in safe mode.makeCharLiteral
(NlsString str) Creates a character string literal from anNlsString
.makeCorrel
(RelDataType type, CorrelationId id) Creates an expression referencing a correlation variable.makeDateLiteral
(Calendar calendar) Deprecated.makeDateLiteral
(DateString date) Creates a Date literal.makeDynamicParam
(RelDataType type, int index) Creates a reference to a dynamic parameter.makeExactLiteral
(@Nullable BigDecimal bd, RelDataType type) Creates a numeric literal.Creates a numeric literal.makeFieldAccess
(RexNode expr, int i) Creates an expression accessing a field with a given ordinal from a record.makeFieldAccess
(RexNode expr, String fieldName, boolean caseSensitive) Creates an expression accessing a given named field from a record.Creates a literal representing a flag.Creates aRexNode
representation a SQL "arg IN (point, ...)" expression.makeInputRef
(RelNode input, int i) Creates a reference to a given field of the input relational expression.makeInputRef
(RelDataType type, int i) Creates a reference to a given field of the input record.makeIntervalLiteral
(@Nullable BigDecimal v, SqlIntervalQualifier intervalQualifier) Creates a literal representing an interval value, for exampleINTERVAL '3-7' YEAR TO MONTH
.makeIntervalLiteral
(SqlIntervalQualifier intervalQualifier) Creates a literal representing an interval type, for exampleYEAR TO MONTH
orDOW
.makeLambdaCall
(RexNode expr, List<RexLambdaRef> parameters) Creates a lambda expression.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.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.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.makeLiteral
(@Nullable Object value, RelDataType type, boolean allowCast, boolean trim) Creates a literal of a given type.Creates a character string literal.makeLocalRef
(RelDataType type, int i) Create a reference to local variable.makeNewInvocation
(RelDataType type, List<RexNode> exprs) Creates an invocation of the NEW operator.makeNotNull
(RexNode exp) Makes a cast of an expression to NOT NULL; returns the expression unchanged if its type already has NOT NULL.makeNullable
(RexNode exp) Makes a cast of an expression to nullable; returns the expression unchanged if its type is already nullable.makeNullable
(RexNode exp, boolean nullability) Makes a cast of an expression to the required nullability; returns the expression unchanged if its type already has the desired nullability.makeNullLiteral
(RelDataType type) Creates a literal whose value is NULL, with a particular type.makeNullLiteral
(SqlTypeName typeName) Deprecated.makeNullLiteral
(SqlTypeName typeName, int precision) Deprecated.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.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.makeOver
(RelDataType type, SqlAggFunction operator, List<RexNode> exprs, List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, RexWindowExclusion exclude, boolean rows, boolean allowPartial, boolean nullWhenCountZero, boolean distinct, boolean ignoreNulls) Creates a call to a windowed agg.makePatternFieldRef
(String alpha, RelDataType type, int i) Creates a reference to a given field of the pattern.protected RexLiteral
Creates a character string literal with type CHAR and default charset and collation.protected RexLiteral
makePreciseStringLiteral
(org.apache.calcite.avatica.util.ByteString value, String charsetName, SqlCollation collation) Creates a character string literal with type CHAR.makeRangeReference
(RelNode input) Creates a reference to all the fields in the row.makeRangeReference
(RelDataType type, int offset, boolean nullable) Creates a reference to all the fields in the row.makeReinterpretCast
(RelDataType type, RexNode exp, RexNode checkOverflow) Makes a reinterpret cast.makeReinterpretCast
(SqlParserPos pos, RelDataType type, RexNode exp, RexNode checkOverflow) Makes a reinterpret cast.makeSearchArgumentLiteral
(Sarg s, RelDataType type) Creates a search argument literal.makeTimeLiteral
(Calendar calendar, int precision) Deprecated.makeTimeLiteral
(TimeString time, int precision) Creates a Time literal.makeTimestampLiteral
(Calendar calendar, int precision) Deprecated.makeTimestampLiteral
(TimestampString timestamp, int precision) Creates a Timestamp literal.makeTimestampTzLiteral
(TimestampWithTimeZoneString timestamp, int precision) makeTimestampWithLocalTimeZoneLiteral
(TimestampString timestamp, int precision) Creates a Timestamp with local time-zone literal.makeTimeTzLiteral
(TimeWithTimeZoneString time, int precision) Creates a Time with time-zone literal.makeTimeWithLocalTimeZoneLiteral
(TimeString time, int precision) Creates a Time with local time-zone literal.makeWindow
(List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean rows) Creates a window specification.makeWindow
(List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean rows, RexWindowExclusion exclude) Creates a window specification.makeZeroLiteral
(RelDataType type) Creates a literal of the default value for the given type.matchNullability
(RelDataType type, RexNode value) Ensures that a type's nullability matches a value's nullability.multiplyDivide
(RexNode e, BigDecimal multiplier, BigDecimal divider) multiplyDivide
(SqlParserPos pos, RexNode e, BigDecimal multiplier, BigDecimal divider)
-
Field Details
-
GET_OPERATOR
Special operator that accesses an unadvertised field of an input record. This operator cannot be used in SQL queries; it is introduced temporarily during sql-to-rel translation, then replaced during the process that trims unwanted fields. -
typeFactory
-
-
Constructor Details
-
RexBuilder
Creates a RexBuilder.- Parameters:
typeFactory
- Type factory
-
-
Method Details
-
identityProjects
Creates a list ofRexInputRef
expressions, projecting the fields of a given record type. -
getTypeFactory
Returns this RexBuilder's type factory.- Returns:
- type factory
-
getOpTab
Returns this RexBuilder's operator table.- Returns:
- operator table
-
makeFieldAccess
Creates an expression accessing a given named field from a record.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-codetrue
if you are sure that the field name is internally generated. Hard-codingfalse
is almost certainly wrong.- Parameters:
expr
- Expression yielding a recordfieldName
- Name of field in recordcaseSensitive
- Whether match is case-sensitive- Returns:
- Expression accessing a given named field
-
makeFieldAccess
Creates an expression accessing a field with a given ordinal from a record.- Parameters:
expr
- Expression yielding a recordi
- Ordinal of field- Returns:
- Expression accessing given field
-
makeCall
Creates a call with a list of arguments and a predetermined type. -
makeCall
public RexNode makeCall(SqlParserPos pos, RelDataType returnType, SqlOperator op, List<RexNode> exprs) Creates a call with a list of arguments and a predetermined type.- Parameters:
pos
- should be different from ZERO if the call can fail at runtime.
-
makeCall
Creates a call with an array of arguments.If you already know the return type of the call, then
makeCall(SqlParserPos, RelDataType, SqlOperator, List)
is preferred. -
makeCall
Creates a call with an array of arguments.- Parameters:
pos
- should be different from ZERO if the call can fail at runtime.If you already know the return type of the call, then
makeCall(SqlParserPos, RelDataType, SqlOperator, List)
is preferred.
-
makeCall
Creates a call with a list of arguments.Equivalent to
makeCall(ZERO, op, exprList.toArray(new RexNode[exprList.size()]))
. -
makeCall
Creates a call with a list of arguments.- Parameters:
pos
- should be different from ZERO if the call can fail at runtime.Equivalent to
makeCall(pos, op, exprList.toArray(new RexNode[exprList.size()]))
.
-
deriveReturnType
Derives the return type of a call to an operator.- Parameters:
op
- the operator being calledexprs
- actual operands- Returns:
- derived type
-
addAggCall
public 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.Argument types help to optimize for repeated aggregates. For instance count(42) is equivalent to count(*).
- Parameters:
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- Returns:
- Rex expression for the given aggregate call
-
addAggCall
@Deprecated public RexNode addAggCall(AggregateCall aggCall, int groupCount, List<AggregateCall> aggCalls, Map<AggregateCall, RexNode> aggCallMapping, @Nullable List<RelDataType> aggArgTypes) Deprecated. -
addAggCall
@Deprecated public RexNode addAggCall(AggregateCall aggCall, int groupCount, boolean indicator, List<AggregateCall> aggCalls, Map<AggregateCall, RexNode> aggCallMapping, @Nullable List<RelDataType> aggArgTypes) Deprecated.Creates a reference to an aggregate call, checking for repeated calls. -
makeOver
@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) Deprecated. -
makeOver
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) Creates a call to a windowed agg. -
makeOver
public RexNode makeOver(RelDataType type, SqlAggFunction operator, List<RexNode> exprs, List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, RexWindowExclusion exclude, boolean rows, boolean allowPartial, boolean nullWhenCountZero, boolean distinct, boolean ignoreNulls) Creates a call to a windowed agg. -
makeWindow
public RexWindow makeWindow(List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean rows) Creates a window specification.- Parameters:
partitionKeys
- Partition keysorderKeys
- Order keyslowerBound
- Lower boundupperBound
- Upper boundrows
- Whether physical. True if row-based, false if range-based- Returns:
- window specification
-
makeWindow
public RexWindow makeWindow(List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean rows, RexWindowExclusion exclude) Creates a window specification.- Parameters:
partitionKeys
- Partition keysorderKeys
- Order keyslowerBound
- Lower boundupperBound
- Upper boundrows
- Whether physical. True if row-based, false if range-based- Returns:
- window specification
-
constantNull
Deprecated.UsemakeNullLiteral(RelDataType)
, which produces a NULL of the correct typeCreates a constant for the SQLNULL
value. -
makeCorrel
Creates an expression referencing a correlation variable.- Parameters:
type
- Type of variableid
- Name of variable- Returns:
- Correlation variable
-
makeNewInvocation
Creates an invocation of the NEW operator.- Parameters:
type
- Type to be instantiatedexprs
- Arguments to NEW operator- Returns:
- Expression invoking NEW operator
-
makeCast
Creates a call to the CAST operator.- Parameters:
type
- Type to cast toexp
- Expression being cast- Returns:
- Call to CAST operator
-
makeCast
Creates a call to the CAST operator.- Parameters:
pos
- Parser position of the cast.type
- Type to cast toexp
- Expression being cast- Returns:
- Call to CAST operator
-
makeCast
Deprecated. -
makeCast
public RexNode makeCast(SqlParserPos pos, RelDataType type, RexNode exp, boolean matchNullability, boolean safe) Creates a call to the CAST operator, expanding if possible, and optionally also preserving nullability, and optionally in safe mode.Tries to expand the cast, and therefore the result may be something other than a
RexCall
to the CAST operator, such as aRexLiteral
.- Parameters:
pos
- Parser positiontype
- Type to cast toexp
- Expression being castmatchNullability
- Whether to ensure the result has the same nullability astype
safe
- Whether to return NULL if cast fails- Returns:
- Call to CAST operator
-
makeCast
Creates a call to the CAST operator, expanding if possible, and optionally also preserving nullability, and optionally in safe mode.Tries to expand the cast, and therefore the result may be something other than a
RexCall
to the CAST operator, such as aRexLiteral
.- Parameters:
type
- Type to cast toexp
- Expression being castmatchNullability
- Whether to ensure the result has the same nullability astype
safe
- Whether to return NULL if cast fails- Returns:
- Call to CAST operator
-
makeCast
public RexNode makeCast(RelDataType type, RexNode exp, boolean matchNullability, boolean safe, RexLiteral format) Creates a call to the CAST operator, expanding if possible, and optionally also preserving nullability, and optionally in safe mode.Tries to expand the cast, and therefore the result may be something other than a
RexCall
to the CAST operator, such as aRexLiteral
.- Parameters:
type
- Type to cast toexp
- Expression being castmatchNullability
- Whether to ensure the result has the same nullability astype
safe
- Whether to return NULL if cast failsformat
- Type Format to cast into- Returns:
- Call to CAST operator
-
makeCast
public RexNode makeCast(SqlParserPos pos, RelDataType type, RexNode exp, boolean matchNullability, boolean safe, RexLiteral format) Creates a call to the CAST operator, expanding if possible, and optionally also preserving nullability, and optionally in safe mode.Tries to expand the cast, and therefore the result may be something other than a
RexCall
to the CAST operator, such as aRexLiteral
.- Parameters:
pos
- Parser positiontype
- Type to cast toexp
- Expression being castmatchNullability
- Whether to ensure the result has the same nullability astype
safe
- Whether to return NULL if cast failsformat
- Type Format to cast into- Returns:
- Call to CAST operator
-
baseUnit
Returns the lowest granularity unit for the given unit. YEAR and MONTH intervals are stored as months; HOUR, MINUTE, SECOND intervals are stored as milliseconds. -
multiplyDivide
-
multiplyDivide
public RexNode multiplyDivide(SqlParserPos pos, RexNode e, BigDecimal multiplier, BigDecimal divider) -
encodeIntervalOrDecimal
Casts a decimal's integer representation to a decimal node. If the expression is not the expected integer type, then it is casted first.An overflow check may be requested to ensure the internal value does not exceed the maximum value of the decimal type.
- Parameters:
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.- Returns:
- the integer reinterpreted as an opaque decimal type
-
encodeIntervalOrDecimal
public RexNode encodeIntervalOrDecimal(SqlParserPos pos, RexNode value, RelDataType type, boolean checkOverflow) -
decodeIntervalOrDecimal
Retrieves an INTERVAL or DECIMAL node's integer representation.- Parameters:
node
- the interval or decimal value as an opaque type- Returns:
- an integer representation of the decimal value
-
decodeIntervalOrDecimal
-
makeAbstractCast
Deprecated. -
makeAbstractCast
Creates a call to CAST or SAFE_CAST operator.- Parameters:
type
- Type to cast toexp
- Expression being castsafe
- Whether to return NULL if cast fails- Returns:
- Call to CAST operator
-
makeAbstractCast
Creates a call to CAST or SAFE_CAST operator.- Parameters:
pos
- Parser position.type
- Type to cast toexp
- Expression being castsafe
- Whether to return NULL if cast fails- Returns:
- Call to CAST operator Casts can fail at runtime, so we expect position information.
-
makeAbstractCast
Creates a call to CAST or SAFE_CAST operator with a FORMAT clause.- Parameters:
type
- Type to cast toexp
- Expression being castsafe
- Whether to return NULL if cast failsformat
- Conversion format for target type- Returns:
- Call to CAST operator
-
makeAbstractCast
public RexNode makeAbstractCast(SqlParserPos pos, RelDataType type, RexNode exp, boolean safe, RexLiteral format) Creates a call to CAST or SAFE_CAST operator with a FORMAT clause.- Parameters:
pos
- Parser positiontype
- Type to cast toexp
- Expression being castsafe
- Whether to return NULL if cast failsformat
- Conversion format for target type- Returns:
- Call to CAST operator
-
makeReinterpretCast
Makes a reinterpret cast.- Parameters:
type
- type returned by the castexp
- expression to be castedcheckOverflow
- whether an overflow check is required- Returns:
- a RexCall with two operands and a special return type
-
makeReinterpretCast
public RexNode makeReinterpretCast(SqlParserPos pos, RelDataType type, RexNode exp, RexNode checkOverflow) Makes a reinterpret cast.- Parameters:
pos
- parser positiontype
- type returned by the castexp
- expression to be castcheckOverflow
- whether an overflow check is required- Returns:
- a RexCall with two operands and a special return type
-
makeNullable
Makes a cast of an expression to nullable; returns the expression unchanged if its type is already nullable. -
makeNotNull
Makes a cast of an expression to NOT NULL; returns the expression unchanged if its type already has NOT NULL. -
makeNullable
Makes a cast of an expression to the required nullability; returns the expression unchanged if its type already has the desired nullability. -
makeRangeReference
Creates a reference to all the fields in the row. That is, the whole row as a single record object.- Parameters:
input
- Input relational expression
-
makeRangeReference
Creates a reference to all the fields in the row.For example, if the input row has type
T{f0,f1,f2,f3,f4}
thenmakeRangeReference(T{f0,f1,f2,f3,f4}, S{f3,f4}, 3)
is an expression which yields the last 2 fields.- Parameters:
type
- Type of the resulting range record.offset
- Index of first field.nullable
- Whether the record is nullable.
-
makeInputRef
Creates a reference to a given field of the input record.- Parameters:
type
- Type of fieldi
- Ordinal of field- Returns:
- Reference to field
-
makeInputRef
Creates a reference to a given field of the input relational expression.- Parameters:
input
- Input relational expressioni
- Ordinal of field- Returns:
- Reference to field
- See Also:
-
makePatternFieldRef
Creates a reference to a given field of the pattern.- Parameters:
alpha
- the pattern nametype
- Type of fieldi
- Ordinal of field- Returns:
- Reference to field of pattern
-
makeLocalRef
Create a reference to local variable.- Parameters:
type
- Type of variablei
- Ordinal of variable- Returns:
- Reference to local variable
-
makeFlag
Creates a literal representing a flag.- Parameters:
flag
- Flag value
-
makeLiteral
Internal method to create a call to a literal. Code outside this package should call one of the type-specific methods such asmakeDateLiteral(DateString)
,makeLiteral(boolean)
,makeLiteral(String)
.- Parameters:
o
- Value of literal, must be appropriate for the typetype
- Type of literaltypeName
- SQL type of literal- Returns:
- Literal
-
makeLiteral
Creates a boolean literal. -
makeExactLiteral
Creates a numeric literal. -
makeBigintLiteral
Creates a BIGINT literal. -
makeExactLiteral
Creates a numeric literal. -
makeBinaryLiteral
Creates a byte array literal. -
makeApproxLiteral
Creates a double-precision literal. -
makeApproxLiteral
Creates an approximate numeric literal (double or float).- Parameters:
bd
- literal valuetype
- approximate numeric type- Returns:
- new literal
-
makeApproxLiteral
Creates an approximate numeric literal (double or float) from a Double value.- Parameters:
val
- literal valuetype
- approximate numeric type- Returns:
- new literal
-
makeSearchArgumentLiteral
Creates a search argument literal. -
makeLiteral
Creates a character string literal. -
makePreciseStringLiteral
Creates a character string literal with type CHAR and default charset and collation.- Parameters:
s
- String value- Returns:
- Character string literal
-
makePreciseStringLiteral
protected RexLiteral makePreciseStringLiteral(org.apache.calcite.avatica.util.ByteString value, String charsetName, SqlCollation collation) Creates a character string literal with type CHAR.- Parameters:
value
- String value in bytescharsetName
- SQL-level charset namecollation
- Sql collation- Returns:
- String literal
-
ensureType
Ensures expression is interpreted as a specified type. The returned expression may be wrapped with a cast.- Parameters:
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 nullability- Returns:
- a casted expression or the original expression
-
ensureType
public RexNode ensureType(SqlParserPos pos, RelDataType type, RexNode node, boolean matchNullability) Ensures expression is interpreted as a specified type. The returned expression may be wrapped with a cast.- Parameters:
pos
- parser positiontype
- 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 nullability- Returns:
- a casted expression or the original expression
-
matchNullability
Ensures that a type's nullability matches a value's nullability. -
makeCharLiteral
Creates a character string literal from anNlsString
.If the string's charset and collation are not set, uses the system defaults.
-
makeDateLiteral
Deprecated. -
makeDateLiteral
Creates a Date literal. -
makeTimeLiteral
Deprecated. -
makeTimeLiteral
Creates a Time literal. -
makeTimeWithLocalTimeZoneLiteral
Creates a Time with local time-zone literal. -
makeTimeTzLiteral
Creates a Time with time-zone literal. -
makeTimestampLiteral
Deprecated. -
makeTimestampLiteral
Creates a Timestamp literal. -
makeTimestampWithLocalTimeZoneLiteral
Creates a Timestamp with local time-zone literal. -
makeTimestampTzLiteral
-
makeIntervalLiteral
Creates a literal representing an interval type, for exampleYEAR TO MONTH
orDOW
. -
makeIntervalLiteral
public RexLiteral makeIntervalLiteral(@Nullable BigDecimal v, SqlIntervalQualifier intervalQualifier) Creates a literal representing an interval value, for exampleINTERVAL '3-7' YEAR TO MONTH
. -
makeDynamicParam
Creates a reference to a dynamic parameter.- Parameters:
type
- Type of dynamic parameterindex
- Index of dynamic parameter- Returns:
- Expression referencing dynamic parameter
-
makeNullLiteral
Creates a literal whose value is NULL, with a particular type.The typing is necessary because RexNodes are strictly typed. For example, in the Rex world the
NULL
parameter toSUBSTRING(NULL FROM 2 FOR 4)
must have a valid VARCHAR type so that the result type can be determined.- Parameters:
type
- Type to cast NULL to- Returns:
- NULL literal of given type
-
makeNullLiteral
Deprecated. -
makeNullLiteral
Deprecated. -
makeIn
-
makeBetween
-
copy
Creates a copy of an expression, which may have been created using a different RexBuilder and/orRelDataTypeFactory
, using this RexBuilder.- Parameters:
expr
- Expression- Returns:
- Copy of expression
- See Also:
-
makeZeroLiteral
Creates a literal of the default value for the given type.This value is:
- 0 for numeric types;
- FALSE for BOOLEAN;
- The epoch for TIMESTAMP and DATE;
- Midnight for TIME;
- The empty string for string types (CHAR, BINARY, VARCHAR, VARBINARY).
- Parameters:
type
- Type- Returns:
- Simple literal
-
makeLiteral
Creates a literal of a given type, padding values of constant-width types to match their type, not allowing casts.- Parameters:
value
- Valuetype
- Type- Returns:
- Simple literal
-
makeLiteral
Creates a literal of a given type, padding values of constant-width types to match their type.- Parameters:
value
- Valuetype
- TypeallowCast
- Whether to allow a cast. If false, value is always aRexLiteral
but may not be the exact type- Returns:
- Simple literal, or cast simple literal
-
makeLiteral
public RexNode makeLiteral(@Nullable Object value, RelDataType type, boolean allowCast, boolean trim) Creates a literal of a given type. The value is assumed to be compatible with the type.The
trim
parameter controls whether to trim values of constant-width types such asCHAR
. Consider a call tomakeLiteral("foo ", CHAR(5)
, and note that the value is too short for its type. Iftrim
is true, the value is converted to "foo" and the type toCHAR(3)
; iftrim
is false, the value is right-padded with spaces to"foo "
, to match the typeCHAR(5)
.- Parameters:
value
- Valuetype
- TypeallowCast
- Whether to allow a cast. If false, value is always aRexLiteral
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'- Returns:
- Simple literal, or cast simple literal
-
makeLambdaCall
Creates a lambda expression.- Parameters:
expr
- expression of the lambdaparameters
- parameters of the lambda- Returns:
- RexNode representing the lambda
-
makeNullLiteral(RelDataType)
, which produces a NULL of the correct type