Class RexBuilder
- java.lang.Object
-
- org.apache.calcite.rex.RexBuilder
-
public class RexBuilder extends java.lang.Object
Factory for row expressions.Some common literal values (NULL, TRUE, FALSE, 0, 1, '') are cached.
-
-
Field Summary
Fields Modifier and Type Field Description private RexLiteral
booleanFalse
private RexLiteral
booleanTrue
private RexLiteral
charEmpty
private RexLiteral
constantNull
static SqlSpecialOperator
GET_OPERATOR
Special operator that accesses an unadvertised field of an input record.private static java.math.BigDecimal
INT_MAX
The largest validint
value, as aBigDecimal
.private static java.math.BigDecimal
INT_MIN
The smallest validint
value, as aBigDecimal
.private SqlStdOperatorTable
opTab
protected RelDataTypeFactory
typeFactory
-
Constructor Summary
Constructors Constructor Description RexBuilder(RelDataTypeFactory typeFactory)
Creates a RexBuilder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RexNode
addAggCall(AggregateCall aggCall, int groupCount, boolean indicator, java.util.List<AggregateCall> aggCalls, java.util.Map<AggregateCall,RexNode> aggCallMapping, java.util.List<RelDataType> aggArgTypes)
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.(package private) boolean
canRemoveCastFromLiteral(RelDataType toType, java.lang.Comparable value, SqlTypeName fromTypeName)
private static java.lang.Object
clean(java.lang.Object o, RelDataType type)
Converts the type of a value to comply withRexLiteral.valueMatchesType(java.lang.Comparable, org.apache.calcite.sql.type.SqlTypeName, boolean)
.RexLiteral
constantNull()
Creates a constant for the SQLNULL
value.RexNode
copy(RexNode expr)
Creates a copy of an expression, which may have been created using a different RexBuilder and/orRelDataTypeFactory
, using this RexBuilder.RexNode
decodeIntervalOrDecimal(RexNode node)
Retrieves an interval or decimal node's integer representationRelDataType
deriveReturnType(SqlOperator op, java.util.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 tableRelDataTypeFactory
getTypeFactory()
Returns this RexBuilder's type factoryprivate RelDataType
guessType(java.lang.Object value)
java.util.List<? extends RexNode>
identityProjects(RelDataType rowType)
Creates a list ofRexInputRef
expressions, projecting the fields of a given record type.RexNode
makeAbstractCast(RelDataType type, RexNode exp)
Creates a call to the CAST operator.RexLiteral
makeApproxLiteral(java.math.BigDecimal bd)
Creates a double-precision literal.RexLiteral
makeApproxLiteral(java.math.BigDecimal bd, RelDataType type)
Creates an approximate numeric literal (double or float).RexLiteral
makeBigintLiteral(java.math.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, java.util.List<RexNode> exprs)
Creates a call with a list of arguments and a predetermined type.RexNode
makeCall(SqlOperator op, java.util.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.private RexNode
makeCastBooleanToExact(RelDataType toType, RexNode exp)
private RexNode
makeCastExactToBoolean(RelDataType toType, RexNode exp)
private RexNode
makeCastIntervalToExact(RelDataType toType, RexNode exp)
RexLiteral
makeCharLiteral(NlsString str)
Creates a character string literal from anNlsString
.RexNode
makeCorrel(RelDataType type, CorrelationId id)
Creates an expression referencing a correlation variable.RexLiteral
makeDateLiteral(java.util.Calendar calendar)
Deprecated.RexLiteral
makeDateLiteral(DateString date)
Creates a Date literal.RexDynamicParam
makeDynamicParam(RelDataType type, int index)
Creates a reference to a dynamic parameterRexLiteral
makeExactLiteral(java.math.BigDecimal bd)
Creates a numeric literal.RexLiteral
makeExactLiteral(java.math.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, java.lang.String fieldName, boolean caseSensitive)
Creates an expression accessing a given named field from a record.private RexNode
makeFieldAccessInternal(RexNode expr, RelDataTypeField field)
Creates an expression accessing a given field from a record.RexLiteral
makeFlag(java.lang.Enum flag)
Creates a literal representing a flag.RexInputRef
makeInputRef(RelNode input, int i)
Creates a reference to a given field of the input relational expression.RexInputRef
makeInputRef(RelDataType type, int i)
Creates a reference to a given field of the input record.RexLiteral
makeIntervalLiteral(java.math.BigDecimal v, SqlIntervalQualifier intervalQualifier)
Creates a literal representing an interval value, for exampleINTERVAL '3-7' YEAR TO MONTH
.RexLiteral
makeIntervalLiteral(SqlIntervalQualifier intervalQualifier)
Creates a literal representing an interval type, for exampleYEAR TO MONTH
orDOW
.RexLiteral
makeLiteral(boolean b)
Creates a boolean literal.protected RexLiteral
makeLiteral(java.lang.Comparable o, RelDataType type, SqlTypeName typeName)
Internal method to create a call to a literal.RexNode
makeLiteral(java.lang.Object value, RelDataType type, boolean allowCast)
Creates a literal of a given type.RexLiteral
makeLiteral(java.lang.String s)
Creates a character string literal.RexNode
makeNewInvocation(RelDataType type, java.util.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, java.util.List<RexNode> exprs, java.util.List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean physical, boolean allowPartial, boolean nullWhenCountZero, boolean distinct)
Creates a call to a windowed agg.RexPatternFieldRef
makePatternFieldRef(java.lang.String alpha, RelDataType type, int i)
Creates a reference to a given field of the pattern.protected RexLiteral
makePreciseStringLiteral(java.lang.String s)
Creates a character string literal with type CHAR and default charset and collation.protected RexLiteral
makePreciseStringLiteral(org.apache.calcite.avatica.util.ByteString value, java.lang.String charsetName, SqlCollation collation)
Creates a character string literal with type CHAR.RexNode
makeRangeReference(RelNode input)
Creates a reference to all the fields in the row.RexRangeRef
makeRangeReference(RelDataType type, int offset, boolean nullable)
Creates a reference to all the fields in the row.RexNode
makeReinterpretCast(RelDataType type, RexNode exp, RexNode checkOverflow)
Makes a reinterpret cast.RexLiteral
makeTimeLiteral(java.util.Calendar calendar, int precision)
Deprecated.RexLiteral
makeTimeLiteral(TimeString time, int precision)
Creates a Time literal.RexLiteral
makeTimestampLiteral(java.util.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(java.util.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.RexNode
multiplyDivide(RexNode e, java.math.BigDecimal multiplier, java.math.BigDecimal divider)
private static java.util.List<java.lang.Integer>
nullableArgs(java.util.List<java.lang.Integer> list0, java.util.List<RelDataType> types)
private static java.lang.String
padRight(java.lang.String s, int length)
Returns a string padded with spaces to make it at least a given length.private static org.apache.calcite.avatica.util.ByteString
padRight(org.apache.calcite.avatica.util.ByteString s, int length)
Returns a byte-string padded with zero bytes to make it at least a given length,private static NlsString
padRight(NlsString s, int length)
Returns anNlsString
with spaces to make it at least a given length.private static java.lang.Comparable
zeroValue(RelDataType type)
-
-
-
Field Detail
-
GET_OPERATOR
public static final SqlSpecialOperator 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.
-
INT_MIN
private static final java.math.BigDecimal INT_MIN
The smallest validint
value, as aBigDecimal
.
-
INT_MAX
private static final java.math.BigDecimal INT_MAX
The largest validint
value, as aBigDecimal
.
-
typeFactory
protected final RelDataTypeFactory typeFactory
-
booleanTrue
private final RexLiteral booleanTrue
-
booleanFalse
private final RexLiteral booleanFalse
-
charEmpty
private final RexLiteral charEmpty
-
constantNull
private final RexLiteral constantNull
-
opTab
private final SqlStdOperatorTable opTab
-
-
Constructor Detail
-
RexBuilder
public RexBuilder(RelDataTypeFactory typeFactory)
Creates a RexBuilder.- Parameters:
typeFactory
- Type factory
-
-
Method Detail
-
identityProjects
public java.util.List<? extends RexNode> identityProjects(RelDataType rowType)
Creates a list ofRexInputRef
expressions, projecting the fields of a given record type.
-
getTypeFactory
public RelDataTypeFactory getTypeFactory()
Returns this RexBuilder's type factory- Returns:
- type factory
-
getOpTab
public SqlStdOperatorTable getOpTab()
Returns this RexBuilder's operator table- Returns:
- operator table
-
makeFieldAccess
public RexNode makeFieldAccess(RexNode expr, java.lang.String fieldName, boolean caseSensitive)
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
public RexNode makeFieldAccess(RexNode expr, int i)
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
-
makeFieldAccessInternal
private RexNode makeFieldAccessInternal(RexNode expr, RelDataTypeField field)
Creates an expression accessing a given field from a record.- Parameters:
expr
- Expression yielding a recordfield
- Field- Returns:
- Expression accessing given field
-
makeCall
public RexNode makeCall(RelDataType returnType, SqlOperator op, java.util.List<RexNode> exprs)
Creates a call with a list of arguments and a predetermined type.
-
makeCall
public RexNode makeCall(SqlOperator op, java.util.List<? extends RexNode> exprs)
Creates a call with an array of arguments.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.
-
makeCall
public final RexNode makeCall(SqlOperator op, RexNode... exprs)
Creates a call with a list of arguments.Equivalent to
makeCall(op, exprList.toArray(new RexNode[exprList.size()]))
.
-
deriveReturnType
public RelDataType deriveReturnType(SqlOperator op, java.util.List<? extends RexNode> exprs)
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, boolean indicator, java.util.List<AggregateCall> aggCalls, java.util.Map<AggregateCall,RexNode> aggCallMapping, java.util.List<RelDataType> aggArgTypes)
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 relationindicator
- Whether the Aggregate has indicator (GROUPING) columnsaggCalls
- destination list of aggregate callsaggCallMapping
- the dictionary of already added callsaggArgTypes
- Argument types, not null- Returns:
- Rex expression for the given aggregate call
-
nullableArgs
private static java.util.List<java.lang.Integer> nullableArgs(java.util.List<java.lang.Integer> list0, java.util.List<RelDataType> types)
-
makeOver
public RexNode makeOver(RelDataType type, SqlAggFunction operator, java.util.List<RexNode> exprs, java.util.List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean physical, boolean allowPartial, boolean nullWhenCountZero, boolean distinct)
Creates a call to a windowed agg.
-
makeWindow
public RexWindow makeWindow(java.util.List<RexNode> partitionKeys, com.google.common.collect.ImmutableList<RexFieldCollation> orderKeys, RexWindowBound lowerBound, RexWindowBound upperBound, boolean isRows)
Creates a window specification.- Parameters:
partitionKeys
- Partition keysorderKeys
- Order keyslowerBound
- Lower boundupperBound
- Upper boundisRows
- Whether physical. True if row-based, false if range-based- Returns:
- window specification
-
constantNull
public RexLiteral constantNull()
Creates a constant for the SQLNULL
value.
-
makeCorrel
public RexNode makeCorrel(RelDataType type, CorrelationId id)
Creates an expression referencing a correlation variable.- Parameters:
id
- Name of variabletype
- Type of variable- Returns:
- Correlation variable
-
makeNewInvocation
public RexNode makeNewInvocation(RelDataType type, java.util.List<RexNode> exprs)
Creates an invocation of the NEW operator.- Parameters:
type
- Type to be instantiatedexprs
- Arguments to NEW operator- Returns:
- Expression invoking NEW operator
-
makeCast
public RexNode makeCast(RelDataType type, RexNode exp)
Creates a call to the CAST operator.- Parameters:
type
- Type to cast toexp
- Expression being cast- Returns:
- Call to CAST operator
-
makeCast
public RexNode makeCast(RelDataType type, RexNode exp, boolean matchNullability)
Creates a call to the CAST operator, expanding if possible, and optionally also preserving nullability.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
- Returns:
- Call to CAST operator
-
baseUnit
protected static org.apache.calcite.avatica.util.TimeUnit baseUnit(SqlTypeName unit)
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.
-
canRemoveCastFromLiteral
boolean canRemoveCastFromLiteral(RelDataType toType, java.lang.Comparable value, SqlTypeName fromTypeName)
-
makeCastExactToBoolean
private RexNode makeCastExactToBoolean(RelDataType toType, RexNode exp)
-
makeCastBooleanToExact
private RexNode makeCastBooleanToExact(RelDataType toType, RexNode exp)
-
makeCastIntervalToExact
private RexNode makeCastIntervalToExact(RelDataType toType, RexNode exp)
-
multiplyDivide
public RexNode multiplyDivide(RexNode e, java.math.BigDecimal multiplier, java.math.BigDecimal divider)
-
encodeIntervalOrDecimal
public RexNode encodeIntervalOrDecimal(RexNode value, RelDataType type, boolean checkOverflow)
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
-
decodeIntervalOrDecimal
public RexNode decodeIntervalOrDecimal(RexNode node)
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
-
makeAbstractCast
public RexNode makeAbstractCast(RelDataType type, RexNode exp)
Creates a call to the CAST operator.- Parameters:
type
- Type to cast toexp
- Expression being cast- Returns:
- Call to CAST operator
-
makeReinterpretCast
public RexNode makeReinterpretCast(RelDataType type, RexNode exp, RexNode checkOverflow)
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
-
makeNotNull
public RexNode makeNotNull(RexNode exp)
Makes a cast of a value to NOT NULL; no-op if the type already has NOT NULL.
-
makeRangeReference
public RexNode makeRangeReference(RelNode input)
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
public RexRangeRef makeRangeReference(RelDataType type, int offset, boolean nullable)
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
public RexInputRef makeInputRef(RelDataType type, int i)
Creates a reference to a given field of the input record.- Parameters:
type
- Type of fieldi
- Ordinal of field- Returns:
- Reference to field
-
makeInputRef
public RexInputRef makeInputRef(RelNode input, int i)
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:
identityProjects(RelDataType)
-
makePatternFieldRef
public RexPatternFieldRef makePatternFieldRef(java.lang.String alpha, RelDataType type, int i)
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
-
makeFlag
public RexLiteral makeFlag(java.lang.Enum flag)
Creates a literal representing a flag.- Parameters:
flag
- Flag value
-
makeLiteral
protected RexLiteral makeLiteral(java.lang.Comparable o, RelDataType type, SqlTypeName typeName)
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
public RexLiteral makeLiteral(boolean b)
Creates a boolean literal.
-
makeExactLiteral
public RexLiteral makeExactLiteral(java.math.BigDecimal bd)
Creates a numeric literal.
-
makeBigintLiteral
public RexLiteral makeBigintLiteral(java.math.BigDecimal bd)
Creates a BIGINT literal.
-
makeExactLiteral
public RexLiteral makeExactLiteral(java.math.BigDecimal bd, RelDataType type)
Creates a numeric literal.
-
makeBinaryLiteral
public RexLiteral makeBinaryLiteral(org.apache.calcite.avatica.util.ByteString byteString)
Creates a byte array literal.
-
makeApproxLiteral
public RexLiteral makeApproxLiteral(java.math.BigDecimal bd)
Creates a double-precision literal.
-
makeApproxLiteral
public RexLiteral makeApproxLiteral(java.math.BigDecimal bd, RelDataType type)
Creates an approximate numeric literal (double or float).- Parameters:
bd
- literal valuetype
- approximate numeric type- Returns:
- new literal
-
makeLiteral
public RexLiteral makeLiteral(java.lang.String s)
Creates a character string literal.
-
makePreciseStringLiteral
protected RexLiteral makePreciseStringLiteral(java.lang.String s)
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, java.lang.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
public RexNode ensureType(RelDataType type, RexNode node, boolean matchNullability)
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
-
matchNullability
public RelDataType matchNullability(RelDataType type, RexNode value)
Ensures that a type's nullability matches a value's nullability.
-
makeCharLiteral
public RexLiteral makeCharLiteral(NlsString str)
Creates a character string literal from anNlsString
.If the string's charset and collation are not set, uses the system defaults.
-
makeDateLiteral
@Deprecated public RexLiteral makeDateLiteral(java.util.Calendar calendar)
Deprecated.
-
makeDateLiteral
public RexLiteral makeDateLiteral(DateString date)
Creates a Date literal.
-
makeTimeLiteral
@Deprecated public RexLiteral makeTimeLiteral(java.util.Calendar calendar, int precision)
Deprecated.
-
makeTimeLiteral
public RexLiteral makeTimeLiteral(TimeString time, int precision)
Creates a Time literal.
-
makeTimeWithLocalTimeZoneLiteral
public RexLiteral makeTimeWithLocalTimeZoneLiteral(TimeString time, int precision)
Creates a Time with local time-zone literal.
-
makeTimestampLiteral
@Deprecated public RexLiteral makeTimestampLiteral(java.util.Calendar calendar, int precision)
Deprecated.
-
makeTimestampLiteral
public RexLiteral makeTimestampLiteral(TimestampString timestamp, int precision)
Creates a Timestamp literal.
-
makeTimestampWithLocalTimeZoneLiteral
public RexLiteral makeTimestampWithLocalTimeZoneLiteral(TimestampString timestamp, int precision)
Creates a Timestamp with local time-zone literal.
-
makeIntervalLiteral
public RexLiteral makeIntervalLiteral(SqlIntervalQualifier intervalQualifier)
Creates a literal representing an interval type, for exampleYEAR TO MONTH
orDOW
.
-
makeIntervalLiteral
public RexLiteral makeIntervalLiteral(java.math.BigDecimal v, SqlIntervalQualifier intervalQualifier)
Creates a literal representing an interval value, for exampleINTERVAL '3-7' YEAR TO MONTH
.
-
makeDynamicParam
public RexDynamicParam makeDynamicParam(RelDataType type, int index)
Creates a reference to a dynamic parameter- Parameters:
type
- Type of dynamic parameterindex
- Index of dynamic parameter- Returns:
- Expression referencing dynamic parameter
-
makeNullLiteral
public RexLiteral makeNullLiteral(RelDataType type)
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 public RexNode makeNullLiteral(SqlTypeName typeName, int precision)
Deprecated.
-
makeNullLiteral
@Deprecated public RexNode makeNullLiteral(SqlTypeName typeName)
Deprecated.
-
copy
public RexNode copy(RexNode expr)
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:
RelDataTypeFactory.copyType(RelDataType)
-
makeZeroLiteral
public RexNode makeZeroLiteral(RelDataType type)
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, or cast simple literal
-
zeroValue
private static java.lang.Comparable zeroValue(RelDataType type)
-
makeLiteral
public RexNode makeLiteral(java.lang.Object value, RelDataType type, boolean allowCast)
Creates a literal of a given type. The value is assumed to be compatible with the 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
-
clean
private static java.lang.Object clean(java.lang.Object o, RelDataType type)
Converts the type of a value to comply withRexLiteral.valueMatchesType(java.lang.Comparable, org.apache.calcite.sql.type.SqlTypeName, boolean)
.
-
guessType
private RelDataType guessType(java.lang.Object value)
-
padRight
private static NlsString padRight(NlsString s, int length)
Returns anNlsString
with spaces to make it at least a given length.
-
padRight
private static java.lang.String padRight(java.lang.String s, int length)
Returns a string padded with spaces to make it at least a given length.
-
padRight
private static org.apache.calcite.avatica.util.ByteString padRight(org.apache.calcite.avatica.util.ByteString s, int length)
Returns a byte-string padded with zero bytes to make it at least a given length,
-
-