Interface RelDataTypeSystem
- All Known Implementing Classes:
DelegatingTypeSystem,RelDataTypeSystemImpl
Provides behaviors concerning type limits and behaviors. For example, in the default system, a DECIMAL can have maximum precision 19, but Hive overrides to 38.
The default implementation is DEFAULT.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionderiveAvgAggType(RelDataTypeFactory typeFactory, RelDataType argumentType) Returns the return type of a call to theAVG,STDDEVorVARaggregate functions, inferred from its argument type.deriveCovarType(RelDataTypeFactory typeFactory, RelDataType arg0Type, RelDataType arg1Type) Returns the return type of a call to theCOVARaggregate function, inferred from its argument types.default @Nullable RelDataTypederiveDecimalDivideType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Infers the return type of a decimal division.default @Nullable RelDataTypederiveDecimalModType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Infers the return type of a decimal modulus operation.default @Nullable RelDataTypederiveDecimalMultiplyType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Infers the return type of a decimal multiplication.default @Nullable RelDataTypederiveDecimalPlusType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Infers the return type of a decimal addition.deriveFractionalRankType(RelDataTypeFactory typeFactory) Returns the return type of theCUME_DISTandPERCENT_RANKaggregate functions.deriveRankType(RelDataTypeFactory typeFactory) Returns the return type of theNTILE,RANK,DENSE_RANK, andROW_NUMBERaggregate functions.deriveSumType(RelDataTypeFactory typeFactory, RelDataType argumentType) Returns the return type of a call to theSUMaggregate function, inferred from its argument type.default TimeFrameSetderiveTimeFrameSet(TimeFrameSet frameSet) Returns a list of supported time frames.intgetDefaultPrecision(SqlTypeName typeName) Returns default precision for this type if supported, otherwiseRelDataType.PRECISION_NOT_SPECIFIEDif precision is either unsupported or must be specified explicitly.intgetDefaultScale(SqlTypeName typeName) Returns default scale for this type if supported, otherwiseRelDataType.SCALE_NOT_SPECIFIEDif scale is either unsupported or must be specified explicitly.@Nullable StringgetLiteral(SqlTypeName typeName, boolean isPrefix) Returns the LITERAL string for the type, either PREFIX/SUFFIX.default intDeprecated.default intDeprecated.Replaced bygetMaxScale(org.apache.calcite.sql.type.SqlTypeName)(DECIMAL).intgetMaxPrecision(SqlTypeName typeName) Returns the maximum precision (or length) allowed for this type, orRelDataType.PRECISION_NOT_SPECIFIEDif precision/length are not applicable for this type.intgetMaxScale(SqlTypeName typeName) Returns the maximum scale allowed for this type, orRelDataType.SCALE_NOT_SPECIFIEDif scale is not applicable for this type.intgetMinPrecision(SqlTypeName typeName) Returns the minimum precision (or length) allowed for this type, orRelDataType.PRECISION_NOT_SPECIFIEDif precision/length are not applicable for this type.intgetMinScale(SqlTypeName typeName) Returns the minimum scale allowed for this type, orRelDataType.SCALE_NOT_SPECIFIEDif scale are not applicable for this type.intgetNumTypeRadix(SqlTypeName typeName) Returns the numeric type radix, typically 2 or 10.booleanisAutoincrement(SqlTypeName typeName) Returns whether the type can be auto increment.booleanisCaseSensitive(SqlTypeName typeName) Returns whether the type is case sensitive.booleanWhether two record types are considered distinct if their field names are the same but in different cases.default booleanReturns whether a MAP type is allowed to have nullable keys.Returns the rounding behavior for numerical operations capable of discarding precision.booleanWhether the least restrictive type of a number of CHAR types of different lengths should be a VARCHAR type.default booleanshouldUseDoubleMultiplication(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Returns whether a decimal multiplication should be implemented by casting arguments to double values.
-
Field Details
-
DEFAULT
Default type system.
-
-
Method Details
-
getMaxScale
Returns the maximum scale allowed for this type, orRelDataType.SCALE_NOT_SPECIFIEDif scale is not applicable for this type.- Returns:
- Maximum allowed scale
-
getMinScale
Returns the minimum scale allowed for this type, orRelDataType.SCALE_NOT_SPECIFIEDif scale are not applicable for this type.- Returns:
- Minimum allowed scale
-
getDefaultPrecision
Returns default precision for this type if supported, otherwiseRelDataType.PRECISION_NOT_SPECIFIEDif precision is either unsupported or must be specified explicitly.- Returns:
- Default precision
-
getDefaultScale
Returns default scale for this type if supported, otherwiseRelDataType.SCALE_NOT_SPECIFIEDif scale is either unsupported or must be specified explicitly.- Returns:
- Default scale
-
getMaxPrecision
Returns the maximum precision (or length) allowed for this type, orRelDataType.PRECISION_NOT_SPECIFIEDif precision/length are not applicable for this type.- Returns:
- Maximum allowed precision
-
getMinPrecision
Returns the minimum precision (or length) allowed for this type, orRelDataType.PRECISION_NOT_SPECIFIEDif precision/length are not applicable for this type.- Returns:
- Minimum allowed precision
-
getMaxNumericScale
Deprecated.Replaced bygetMaxScale(org.apache.calcite.sql.type.SqlTypeName)(DECIMAL).From Calcite release 1.38 onwards, instead of calling this method, you should call
getMaxScale(DECIMAL).In Calcite release 1.38, if you wish to change the maximum scale of
SqlTypeName.DECIMALvalues, you should do two things:- Override the
getMaxScale(SqlTypeName)method, changing its behavior forDECIMAL; - Make sure that the implementation of your
#getMaxNumericScalemethod callsgetMaxScale(DECIMAL).
In Calcite release 1.39, Calcite will cease calling this method, and will remove the override of the method in
RelDataTypeSystemImpl. You should remove all calls to and overrides of this method.Returns the maximum scale of a NUMERIC or DECIMAL type. Default value is 19. - Override the
-
getMaxNumericPrecision
Deprecated.Replaced bygetMaxScale(org.apache.calcite.sql.type.SqlTypeName)(DECIMAL).From Calcite release 1.38 onwards, instead of calling this method, you should call
getMaxPrecision(DECIMAL).In Calcite release 1.38, if you wish to change the maximum precision of
SqlTypeName.DECIMALvalues, you should do two things:- Override the
getMaxPrecision(SqlTypeName)method, changing its behavior forDECIMAL; - Make sure that the implementation of your
#getMaxNumericPrecisionmethod callsgetMaxPrecision(DECIMAL).
In Calcite release 1.39, Calcite will cease calling this method, and will remove the override of the method in
RelDataTypeSystemImpl. You should remove all calls to and overrides of this method.Returns the maximum precision of a NUMERIC or DECIMAL type. Default value is 19. - Override the
-
roundingMode
RoundingMode roundingMode()Returns the rounding behavior for numerical operations capable of discarding precision. -
mapKeysCanBeNullable
default boolean mapKeysCanBeNullable()Returns whether a MAP type is allowed to have nullable keys. -
getLiteral
Returns the LITERAL string for the type, either PREFIX/SUFFIX. -
isCaseSensitive
Returns whether the type is case sensitive. -
isAutoincrement
Returns whether the type can be auto increment. -
getNumTypeRadix
Returns the numeric type radix, typically 2 or 10. 0 means "not applicable". -
deriveSumType
Returns the return type of a call to theSUMaggregate function, inferred from its argument type. -
deriveAvgAggType
Returns the return type of a call to theAVG,STDDEVorVARaggregate functions, inferred from its argument type. -
deriveCovarType
RelDataType deriveCovarType(RelDataTypeFactory typeFactory, RelDataType arg0Type, RelDataType arg1Type) Returns the return type of a call to theCOVARaggregate function, inferred from its argument types. -
deriveFractionalRankType
Returns the return type of theCUME_DISTandPERCENT_RANKaggregate functions. -
deriveRankType
Returns the return type of theNTILE,RANK,DENSE_RANK, andROW_NUMBERaggregate functions. -
isSchemaCaseSensitive
boolean isSchemaCaseSensitive()Whether two record types are considered distinct if their field names are the same but in different cases. -
shouldConvertRaggedUnionTypesToVarying
boolean shouldConvertRaggedUnionTypesToVarying()Whether the least restrictive type of a number of CHAR types of different lengths should be a VARCHAR type. And similarly BINARY to VARBINARY. -
shouldUseDoubleMultiplication
default boolean shouldUseDoubleMultiplication(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Returns whether a decimal multiplication should be implemented by casting arguments to double values.Pre-condition:
createDecimalProduct(type1, type2) != null -
deriveDecimalPlusType
default @Nullable RelDataType deriveDecimalPlusType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Infers the return type of a decimal addition. Decimal addition involves at least one decimal operand and requires both operands to have exact numeric types.Rules:
- 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
- Let d be the number of whole digits in 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
- Parameters:
typeFactory- TypeFactory used to create output typetype1- Type of the first operandtype2- Type of the second operand- Returns:
- Result type for a decimal addition
- See Also:
-
deriveDecimalMultiplyType
default @Nullable RelDataType deriveDecimalMultiplyType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Infers the return type of a decimal multiplication. Decimal multiplication involves at least one decimal operand and requires both operands to have exact numeric types.The default implementation is SQL:2003 compliant.
Rules:
- 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
- Let d be the number of whole digits in the result
- Then the result type is a decimal with:
- p = p1 + p2
- s = s1 + s2
- p and s are capped at their maximum values
p and s are capped at their maximum values
- Parameters:
typeFactory- TypeFactory used to create output typetype1- Type of the first operandtype2- Type of the second operand- Returns:
- Result type for a decimal multiplication, or null if decimal multiplication should not be applied to the operands
- See Also:
-
deriveDecimalDivideType
default @Nullable RelDataType deriveDecimalDivideType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Infers the return type of a decimal division. Decimal division involves at least one decimal operand and requires both operands to have exact numeric types.The default implementation is SQL:2003 compliant.
Rules:
- 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
- Let d be the number of whole digits in the result
- Then the result type is a decimal with:
- d = p1 - s1 + s2
- s = max(6, s1 + p2 + 1)
- p = d + s
- p and s are capped at their maximum values
- Parameters:
typeFactory- TypeFactory used to create output typetype1- Type of the first operandtype2- Type of the second operand- Returns:
- Result type for a decimal division, or null if decimal division should not be applied to the operands
- See Also:
-
deriveDecimalModType
default @Nullable RelDataType deriveDecimalModType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Infers the return type of a decimal modulus operation. Decimal modulus involves at least one decimal operand.The default implementation is SQL:2003 compliant: the declared type of the result is the declared type of the second operand (expression divisor).
- Parameters:
typeFactory- TypeFactory used to create output typetype1- Type of the first operandtype2- Type of the second operand- Returns:
- Result type for a decimal modulus, or null if decimal modulus should not be applied to the operands
- See Also:
-
deriveTimeFrameSet
Returns a list of supported time frames.The validator calls this method with
TimeFrames.COREas an argument, and the default implementation of this method returns its input, and thereforeCOREis the default time frame set.If you wish to use a custom time frame set, create an instance of
RelDataTypeSystemthat overrides this method. Your method should callTimeFrameSet.builder(), will probably add all or most of the time frames in theframeSetargument, and then callTimeFrameSet.Builder.build().- Parameters:
frameSet- Set of built-in time frames
-
getMaxScale(org.apache.calcite.sql.type.SqlTypeName)(DECIMAL).