Package org.apache.calcite.sql.type
Class ReturnTypes
- java.lang.Object
-
- org.apache.calcite.sql.type.ReturnTypes
-
public abstract class ReturnTypes extends java.lang.Object
A collection of return-type inference strategies.
-
-
Field Summary
Fields Modifier and Type Field Description static SqlReturnTypeInference
AGG_SUM
Type-inference strategy for SUM aggregate function inferred from the operand type, and nullable if the call occurs within a "GROUP BY ()" query.static SqlReturnTypeInference
AGG_SUM_EMPTY_IS_ZERO
Type-inference strategy for $SUM0 aggregate function inferred from the operand type.static SqlReturnTypeInference
ARG0
Type-inference strategy whereby the result type of a call is the type of the operand #0 (0-based).static SqlReturnTypeInference
ARG0_FORCE_NULLABLE
Type-inference strategy whereby the result type of a call is the type of the operand #0 (0-based), with nulls always allowed.static SqlReturnTypeInference
ARG0_INTERVAL
static SqlReturnTypeInference
ARG0_INTERVAL_NULLABLE
static SqlReturnTypeInference
ARG0_NULLABLE
Type-inference strategy whereby the result type of a call is the type of the operand #0 (0-based).static SqlReturnTypeInference
ARG0_NULLABLE_IF_EMPTY
Type-inference strategy whereby the result type of a call is the type of the operand #0 (0-based), and nullable if the call occurs within a "GROUP BY ()" query.static SqlReturnTypeInference
ARG0_NULLABLE_VARYING
Type-inference strategy whereby the result type of a call is VARYING the type of the first argument.static SqlReturnTypeInference
ARG0_OR_EXACT_NO_SCALE
Type-inference strategy whereby the result type of a call isDECIMAL_SCALE0
with a fallback toARG0
This rule is used for floor, ceiling.static SqlReturnTypeInference
ARG1
Type-inference strategy whereby the result type of a call is the type of the operand #1 (0-based).static SqlReturnTypeInference
ARG1_NULLABLE
Type-inference strategy whereby the result type of a call is the type of the operand #1 (0-based).static SqlReturnTypeInference
ARG2
Type-inference strategy whereby the result type of a call is the type of operand #2 (0-based).static SqlReturnTypeInference
ARG2_NULLABLE
Type-inference strategy whereby the result type of a call is the type of operand #2 (0-based).static SqlReturnTypeInference
AVG_AGG_FUNCTION
static SqlReturnTypeInference
BIGINT
Type-inference strategy whereby the result type of a call is a Bigintstatic SqlReturnTypeInference
BIGINT_FORCE_NULLABLE
Type-inference strategy whereby the result type of a call is a nullable Bigintstatic SqlReturnTypeInference
BIGINT_NULLABLE
Type-inference strategy whereby the result type of a call is an Bigint with nulls allowed if any of the operands allow nulls.static SqlReturnTypeInference
BOOLEAN
Type-inference strategy whereby the result type of a call is Boolean.static SqlReturnTypeInference
BOOLEAN_FORCE_NULLABLE
Type-inference strategy whereby the result type of a call is a nullable Boolean.static SqlReturnTypeInference
BOOLEAN_NOT_NULL
Type-inference strategy whereby the result type of a call is Boolean not null.static SqlReturnTypeInference
BOOLEAN_NULLABLE
Type-inference strategy whereby the result type of a call is Boolean, with nulls allowed if any of the operands allow nulls.static SqlReturnTypeInference
BOOLEAN_NULLABLE_OPTIMIZED
Type-inference strategy with similar effect toBOOLEAN_NULLABLE
, which is more efficient, but can only be used if all arguments are BOOLEAN.static SqlReturnTypeInference
COLUMN_LIST
Type-inference strategy that always returns "COLUMN_LIST".static SqlReturnTypeInference
COVAR_REGR_FUNCTION
static SqlReturnTypeInference
CURSOR
Type-inference strategy that always returns "CURSOR".static SqlReturnTypeInference
DATE
Type-inference strategy whereby the result type of a call is Date.static SqlReturnTypeInference
DECIMAL_PRODUCT
Type-inference strategy whereby the result type of a call is the decimal product of two exact numeric operands where at least one of the operands is a decimal.static SqlReturnTypeInference
DECIMAL_PRODUCT_NULLABLE
Same asDECIMAL_PRODUCT
but returns with nullability if any of the operands is nullable by usingSqlTypeTransforms.TO_NULLABLE
static SqlReturnTypeInference
DECIMAL_QUOTIENT
Type-inference strategy whereby the result type of a call is the decimal product of two exact numeric operands where at least one of the operands is a decimal.static SqlReturnTypeInference
DECIMAL_QUOTIENT_NULLABLE
Same asDECIMAL_QUOTIENT
but returns with nullability if any of the operands is nullable by usingSqlTypeTransforms.TO_NULLABLE
static SqlReturnTypeInference
DECIMAL_SCALE0
Type-inference strategy for a call where the first argument is a decimal.static SqlReturnTypeInference
DECIMAL_SUM
Type-inference strategy whereby the result type of a call is the decimal sum of two exact numeric operands where at least one of the operands is a decimal.static SqlReturnTypeInference
DECIMAL_SUM_NULLABLE
Same asDECIMAL_SUM
but returns with nullability if any of the operands is nullable by usingSqlTypeTransforms.TO_NULLABLE
.static SqlReturnTypeInference
DOUBLE
Type-inference strategy whereby the result type of a call is Double.static SqlReturnTypeInference
DOUBLE_NULLABLE
Type-inference strategy whereby the result type of a call is Double with nulls allowed if any of the operands allow nulls.static SqlReturnTypeInference
DYADIC_STRING_SUM_PRECISION
Type-inference strategy whereby the result type of a call is the same type as the input types but with the combined length of the two first types if types are of char type the type with the highest coercibility will be used result is varying if either input is; otherwise fixedstatic SqlReturnTypeInference
DYADIC_STRING_SUM_PRECISION_NULLABLE
Same asDYADIC_STRING_SUM_PRECISION
and usingSqlTypeTransforms.TO_NULLABLE
static SqlReturnTypeInference
DYADIC_STRING_SUM_PRECISION_NULLABLE_VARYING
Same asDYADIC_STRING_SUM_PRECISION
and usingSqlTypeTransforms.TO_NULLABLE
,SqlTypeTransforms.TO_VARYING
.static SqlReturnTypeInference
FRACTIONAL_RANK
Type-inference strategy for theCUME_DIST
andPERCENT_RANK
aggregate functions.static SqlReturnTypeInference
HISTOGRAM
Type-inference strategy for Histogram agg supportstatic SqlReturnTypeInference
INTEGER
Type-inference strategy whereby the result type of a call is an Integer.static SqlReturnTypeInference
INTEGER_NULLABLE
Type-inference strategy whereby the result type of a call is an Integer with nulls allowed if any of the operands allow nulls.static SqlReturnTypeInference
INTEGER_QUOTIENT_NULLABLE
Type-inference strategy whereby the result type of a call isARG0_INTERVAL_NULLABLE
andLEAST_RESTRICTIVE
.static SqlReturnTypeInference
LEAST_RESTRICTIVE
Type-inference strategy whereby the result type of a call is using its operands biggest type, using the SQL:1999 rules described in "Data types of results of aggregations".static SqlReturnTypeInference
MULTISET
Returns the same type as the multiset carries.static SqlReturnTypeInference
MULTISET_ELEMENT_NULLABLE
Returns the element type of a multisetstatic SqlReturnTypeInference
MULTISET_NULLABLE
Same asMULTISET
but returns with nullability if any of the operands is nullable.static SqlReturnTypeInference
MULTISET_PROJECT_ONLY
Returns the type of the only column of a multiset.static SqlReturnTypeInference
MULTISET_PROJECT0
Returns a multiset of column #0 of a multiset.static SqlReturnTypeInference
MULTISET_RECORD
Returns a multiset of the first column of a multiset.static SqlReturnTypeInference
NULLABLE_SUM
Type-inference strategy whereby the result type of a call isDECIMAL_SUM_NULLABLE
with a fallback toLEAST_RESTRICTIVE
These rules are used for addition and subtraction.static SqlReturnTypeInference
PRODUCT_NULLABLE
Type-inference strategy whereby the result type of a call isDECIMAL_PRODUCT_NULLABLE
with a fallback toARG0_INTERVAL_NULLABLE
andLEAST_RESTRICTIVE
.static SqlReturnTypeInference
QUOTIENT_NULLABLE
Type-inference strategy whereby the result type of a call isDECIMAL_QUOTIENT_NULLABLE
with a fallback toARG0_INTERVAL_NULLABLE
andLEAST_RESTRICTIVE
These rules are used for division.static SqlReturnTypeInference
RANK
Type-inference strategy for theNTILE
,RANK
,DENSE_RANK
, andROW_NUMBER
aggregate functions.static SqlReturnTypeInference
RECORD_TO_SCALAR
Returns the field type of a structured type which has only one field.static SqlReturnTypeInference
SCOPE
Type-inference strategy where the expression is assumed to be registered as aSqlValidatorNamespace
, and therefore the result type of the call is the type of that namespace.static SqlReturnTypeInference
TIME
Type-inference strategy whereby the result type of a call is Time(0).static SqlReturnTypeInference
TIME_NULLABLE
Type-inference strategy whereby the result type of a call is nullable Time(0).static SqlReturnTypeInference
TO_MULTISET
Returns a multiset type.static SqlReturnTypeInference
VARCHAR_2000
Type-inference strategy that always returns "VARCHAR(2000)".
-
Constructor Summary
Constructors Modifier Constructor Description private
ReturnTypes()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SqlTypeTransformCascade
cascade(SqlReturnTypeInference rule, SqlTypeTransform... transforms)
Creates a return-type inference that applies a rule then a sequence of transforms.static SqlReturnTypeInferenceChain
chain(SqlReturnTypeInference... rules)
static ExplicitReturnTypeInference
explicit(RelDataType type)
Creates an inference rule which returns a copy of a given data type.static ExplicitReturnTypeInference
explicit(RelProtoDataType protoType)
static ExplicitReturnTypeInference
explicit(SqlTypeName typeName)
Creates an inference rule which returns a type with no precision or scale, such asDATE
.static ExplicitReturnTypeInference
explicit(SqlTypeName typeName, int precision)
Creates an inference rule which returns a type with precision but no scale, such asVARCHAR(100)
.
-
-
-
Field Detail
-
ARG0
public static final SqlReturnTypeInference ARG0
Type-inference strategy whereby the result type of a call is the type of the operand #0 (0-based).
-
ARG0_NULLABLE_VARYING
public static final SqlReturnTypeInference ARG0_NULLABLE_VARYING
Type-inference strategy whereby the result type of a call is VARYING the type of the first argument. The length returned is the same as length of the first argument. If any of the other operands are nullable the returned type will also be nullable. First Arg must be of string type.
-
ARG0_NULLABLE
public static final SqlReturnTypeInference ARG0_NULLABLE
Type-inference strategy whereby the result type of a call is the type of the operand #0 (0-based). If any of the other operands are nullable the returned type will also be nullable.
-
ARG0_FORCE_NULLABLE
public static final SqlReturnTypeInference ARG0_FORCE_NULLABLE
Type-inference strategy whereby the result type of a call is the type of the operand #0 (0-based), with nulls always allowed.
-
ARG0_INTERVAL
public static final SqlReturnTypeInference ARG0_INTERVAL
-
ARG0_INTERVAL_NULLABLE
public static final SqlReturnTypeInference ARG0_INTERVAL_NULLABLE
-
ARG0_NULLABLE_IF_EMPTY
public static final SqlReturnTypeInference ARG0_NULLABLE_IF_EMPTY
Type-inference strategy whereby the result type of a call is the type of the operand #0 (0-based), and nullable if the call occurs within a "GROUP BY ()" query. E.g. in "select sum(1) as s from empty", s may be null.
-
ARG1
public static final SqlReturnTypeInference ARG1
Type-inference strategy whereby the result type of a call is the type of the operand #1 (0-based).
-
ARG1_NULLABLE
public static final SqlReturnTypeInference ARG1_NULLABLE
Type-inference strategy whereby the result type of a call is the type of the operand #1 (0-based). If any of the other operands are nullable the returned type will also be nullable.
-
ARG2
public static final SqlReturnTypeInference ARG2
Type-inference strategy whereby the result type of a call is the type of operand #2 (0-based).
-
ARG2_NULLABLE
public static final SqlReturnTypeInference ARG2_NULLABLE
Type-inference strategy whereby the result type of a call is the type of operand #2 (0-based). If any of the other operands are nullable the returned type will also be nullable.
-
BOOLEAN
public static final SqlReturnTypeInference BOOLEAN
Type-inference strategy whereby the result type of a call is Boolean.
-
BOOLEAN_NULLABLE
public static final SqlReturnTypeInference BOOLEAN_NULLABLE
Type-inference strategy whereby the result type of a call is Boolean, with nulls allowed if any of the operands allow nulls.
-
BOOLEAN_NULLABLE_OPTIMIZED
public static final SqlReturnTypeInference BOOLEAN_NULLABLE_OPTIMIZED
Type-inference strategy with similar effect toBOOLEAN_NULLABLE
, which is more efficient, but can only be used if all arguments are BOOLEAN.
-
BOOLEAN_FORCE_NULLABLE
public static final SqlReturnTypeInference BOOLEAN_FORCE_NULLABLE
Type-inference strategy whereby the result type of a call is a nullable Boolean.
-
BOOLEAN_NOT_NULL
public static final SqlReturnTypeInference BOOLEAN_NOT_NULL
Type-inference strategy whereby the result type of a call is Boolean not null.
-
DATE
public static final SqlReturnTypeInference DATE
Type-inference strategy whereby the result type of a call is Date.
-
TIME
public static final SqlReturnTypeInference TIME
Type-inference strategy whereby the result type of a call is Time(0).
-
TIME_NULLABLE
public static final SqlReturnTypeInference TIME_NULLABLE
Type-inference strategy whereby the result type of a call is nullable Time(0).
-
DOUBLE
public static final SqlReturnTypeInference DOUBLE
Type-inference strategy whereby the result type of a call is Double.
-
DOUBLE_NULLABLE
public static final SqlReturnTypeInference DOUBLE_NULLABLE
Type-inference strategy whereby the result type of a call is Double with nulls allowed if any of the operands allow nulls.
-
INTEGER
public static final SqlReturnTypeInference INTEGER
Type-inference strategy whereby the result type of a call is an Integer.
-
INTEGER_NULLABLE
public static final SqlReturnTypeInference INTEGER_NULLABLE
Type-inference strategy whereby the result type of a call is an Integer with nulls allowed if any of the operands allow nulls.
-
BIGINT
public static final SqlReturnTypeInference BIGINT
Type-inference strategy whereby the result type of a call is a Bigint
-
BIGINT_FORCE_NULLABLE
public static final SqlReturnTypeInference BIGINT_FORCE_NULLABLE
Type-inference strategy whereby the result type of a call is a nullable Bigint
-
BIGINT_NULLABLE
public static final SqlReturnTypeInference BIGINT_NULLABLE
Type-inference strategy whereby the result type of a call is an Bigint with nulls allowed if any of the operands allow nulls.
-
VARCHAR_2000
public static final SqlReturnTypeInference VARCHAR_2000
Type-inference strategy that always returns "VARCHAR(2000)".
-
HISTOGRAM
public static final SqlReturnTypeInference HISTOGRAM
Type-inference strategy for Histogram agg support
-
CURSOR
public static final SqlReturnTypeInference CURSOR
Type-inference strategy that always returns "CURSOR".
-
COLUMN_LIST
public static final SqlReturnTypeInference COLUMN_LIST
Type-inference strategy that always returns "COLUMN_LIST".
-
LEAST_RESTRICTIVE
public static final SqlReturnTypeInference LEAST_RESTRICTIVE
Type-inference strategy whereby the result type of a call is using its operands biggest type, using the SQL:1999 rules described in "Data types of results of aggregations". These rules are used in union, except, intersect, case and other places.- See Also:
SQL:1999 Part 2 Section 9.3
-
MULTISET
public static final SqlReturnTypeInference MULTISET
Returns the same type as the multiset carries. The multiset type returned is the least restrictive of the call's multiset operands
-
TO_MULTISET
public static final SqlReturnTypeInference TO_MULTISET
Returns a multiset type.For example, given
INTEGER
, returnsINTEGER MULTISET
.
-
MULTISET_ELEMENT_NULLABLE
public static final SqlReturnTypeInference MULTISET_ELEMENT_NULLABLE
Returns the element type of a multiset
-
MULTISET_NULLABLE
public static final SqlReturnTypeInference MULTISET_NULLABLE
Same asMULTISET
but returns with nullability if any of the operands is nullable.
-
MULTISET_PROJECT_ONLY
public static final SqlReturnTypeInference MULTISET_PROJECT_ONLY
Returns the type of the only column of a multiset.For example, given
RECORD(x INTEGER) MULTISET
, returnsINTEGER MULTISET
.
-
INTEGER_QUOTIENT_NULLABLE
public static final SqlReturnTypeInference INTEGER_QUOTIENT_NULLABLE
Type-inference strategy whereby the result type of a call isARG0_INTERVAL_NULLABLE
andLEAST_RESTRICTIVE
. These rules are used for integer division.
-
DECIMAL_SCALE0
public static final SqlReturnTypeInference DECIMAL_SCALE0
Type-inference strategy for a call where the first argument is a decimal. The result type of a call is a decimal with a scale of 0, and the same precision and nullability as the first argument.
-
ARG0_OR_EXACT_NO_SCALE
public static final SqlReturnTypeInference ARG0_OR_EXACT_NO_SCALE
Type-inference strategy whereby the result type of a call isDECIMAL_SCALE0
with a fallback toARG0
This rule is used for floor, ceiling.
-
DECIMAL_PRODUCT
public static final SqlReturnTypeInference DECIMAL_PRODUCT
Type-inference strategy whereby the result type of a call is the decimal product of two exact numeric operands where at least one of the operands is a decimal.
-
DECIMAL_PRODUCT_NULLABLE
public static final SqlReturnTypeInference DECIMAL_PRODUCT_NULLABLE
Same asDECIMAL_PRODUCT
but returns with nullability if any of the operands is nullable by usingSqlTypeTransforms.TO_NULLABLE
-
PRODUCT_NULLABLE
public static final SqlReturnTypeInference PRODUCT_NULLABLE
Type-inference strategy whereby the result type of a call isDECIMAL_PRODUCT_NULLABLE
with a fallback toARG0_INTERVAL_NULLABLE
andLEAST_RESTRICTIVE
. These rules are used for multiplication.
-
DECIMAL_QUOTIENT
public static final SqlReturnTypeInference DECIMAL_QUOTIENT
Type-inference strategy whereby the result type of a call is the decimal product of two exact numeric operands where at least one of the operands is a decimal.
-
DECIMAL_QUOTIENT_NULLABLE
public static final SqlReturnTypeInference DECIMAL_QUOTIENT_NULLABLE
Same asDECIMAL_QUOTIENT
but returns with nullability if any of the operands is nullable by usingSqlTypeTransforms.TO_NULLABLE
-
QUOTIENT_NULLABLE
public static final SqlReturnTypeInference QUOTIENT_NULLABLE
Type-inference strategy whereby the result type of a call isDECIMAL_QUOTIENT_NULLABLE
with a fallback toARG0_INTERVAL_NULLABLE
andLEAST_RESTRICTIVE
These rules are used for division.
-
DECIMAL_SUM
public static final SqlReturnTypeInference DECIMAL_SUM
Type-inference strategy whereby the result type of a call is the decimal sum of two exact numeric operands where at least one of the operands is a decimal. Let p1, s1 be the precision and scale of the first operand Let p2, s2 be the precision and scale of the second operand Let p, s be the precision and scale of the result, Then the result type is a decimal with:- s = max(s1, s2)
- p = max(p1 - s1, p2 - s2) + s + 1
p and s are capped at their maximum values
- See Also:
SQL:2003 Part 2 Section 6.26
-
DECIMAL_SUM_NULLABLE
public static final SqlReturnTypeInference DECIMAL_SUM_NULLABLE
Same asDECIMAL_SUM
but returns with nullability if any of the operands is nullable by usingSqlTypeTransforms.TO_NULLABLE
.
-
NULLABLE_SUM
public static final SqlReturnTypeInference NULLABLE_SUM
Type-inference strategy whereby the result type of a call isDECIMAL_SUM_NULLABLE
with a fallback toLEAST_RESTRICTIVE
These rules are used for addition and subtraction.
-
DYADIC_STRING_SUM_PRECISION
public static final SqlReturnTypeInference DYADIC_STRING_SUM_PRECISION
Type-inference strategy whereby the result type of a call is- the same type as the input types but with the combined length of the two first types
- if types are of char type the type with the highest coercibility will be used
- result is varying if either input is; otherwise fixed
Pre-requisites:
- input types must be of the same string type
- types must be comparable without casting
-
DYADIC_STRING_SUM_PRECISION_NULLABLE_VARYING
public static final SqlReturnTypeInference DYADIC_STRING_SUM_PRECISION_NULLABLE_VARYING
Same asDYADIC_STRING_SUM_PRECISION
and usingSqlTypeTransforms.TO_NULLABLE
,SqlTypeTransforms.TO_VARYING
.
-
DYADIC_STRING_SUM_PRECISION_NULLABLE
public static final SqlReturnTypeInference DYADIC_STRING_SUM_PRECISION_NULLABLE
Same asDYADIC_STRING_SUM_PRECISION
and usingSqlTypeTransforms.TO_NULLABLE
-
SCOPE
public static final SqlReturnTypeInference SCOPE
Type-inference strategy where the expression is assumed to be registered as aSqlValidatorNamespace
, and therefore the result type of the call is the type of that namespace.
-
MULTISET_PROJECT0
public static final SqlReturnTypeInference MULTISET_PROJECT0
Returns a multiset of column #0 of a multiset. For example, givenRECORD(x INTEGER, y DATE) MULTISET
, returnsINTEGER MULTISET
.
-
MULTISET_RECORD
public static final SqlReturnTypeInference MULTISET_RECORD
Returns a multiset of the first column of a multiset. For example, givenINTEGER MULTISET
, returnsRECORD(x INTEGER) MULTISET
.
-
RECORD_TO_SCALAR
public static final SqlReturnTypeInference RECORD_TO_SCALAR
Returns the field type of a structured type which has only one field. For example, givenRECORD(x INTEGER)
returnsINTEGER
.
-
AGG_SUM
public static final SqlReturnTypeInference AGG_SUM
Type-inference strategy for SUM aggregate function inferred from the operand type, and nullable if the call occurs within a "GROUP BY ()" query. E.g. in "select sum(x) as s from empty", s may be null. Also, with the default implementation of RelDataTypeSystem, s has the same type name as x.
-
AGG_SUM_EMPTY_IS_ZERO
public static final SqlReturnTypeInference AGG_SUM_EMPTY_IS_ZERO
Type-inference strategy for $SUM0 aggregate function inferred from the operand type. By default the inferred type is identical to the operand type. E.g. in "select $sum0(x) as s from empty", s has the same type as x.
-
FRACTIONAL_RANK
public static final SqlReturnTypeInference FRACTIONAL_RANK
Type-inference strategy for theCUME_DIST
andPERCENT_RANK
aggregate functions.
-
RANK
public static final SqlReturnTypeInference RANK
Type-inference strategy for theNTILE
,RANK
,DENSE_RANK
, andROW_NUMBER
aggregate functions.
-
AVG_AGG_FUNCTION
public static final SqlReturnTypeInference AVG_AGG_FUNCTION
-
COVAR_REGR_FUNCTION
public static final SqlReturnTypeInference COVAR_REGR_FUNCTION
-
-
Method Detail
-
chain
public static SqlReturnTypeInferenceChain chain(SqlReturnTypeInference... rules)
-
cascade
public static SqlTypeTransformCascade cascade(SqlReturnTypeInference rule, SqlTypeTransform... transforms)
Creates a return-type inference that applies a rule then a sequence of transforms.
-
explicit
public static ExplicitReturnTypeInference explicit(RelProtoDataType protoType)
-
explicit
public static ExplicitReturnTypeInference explicit(RelDataType type)
Creates an inference rule which returns a copy of a given data type.
-
explicit
public static ExplicitReturnTypeInference explicit(SqlTypeName typeName)
Creates an inference rule which returns a type with no precision or scale, such asDATE
.
-
explicit
public static ExplicitReturnTypeInference explicit(SqlTypeName typeName, int precision)
Creates an inference rule which returns a type with precision but no scale, such asVARCHAR(100)
.
-
-