Package org.apache.calcite.rel.type
Interface RelDataTypeSystem
-
- All Known Implementing Classes:
DelegatingTypeSystem
,RelDataTypeSystemImpl
public interface RelDataTypeSystem
Type system.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 Modifier and Type Field Description static RelDataTypeSystem
DEFAULT
Default type system.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description RelDataType
deriveAvgAggType(RelDataTypeFactory typeFactory, RelDataType argumentType)
Returns the return type of a call to theAVG
,STDDEV
orVAR
aggregate functions, inferred from its argument type.RelDataType
deriveCovarType(RelDataTypeFactory typeFactory, RelDataType arg0Type, RelDataType arg1Type)
Returns the return type of a call to theCOVAR
aggregate function, inferred from its argument types.default RelDataType
deriveDecimalDivideType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2)
Infers the return type of a decimal division.default RelDataType
deriveDecimalModType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2)
Infers the return type of a decimal modulus operation.default RelDataType
deriveDecimalMultiplyType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2)
Infers the return type of a decimal multiplication.default RelDataType
deriveDecimalPlusType(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2)
Infers the return type of a decimal addition.RelDataType
deriveFractionalRankType(RelDataTypeFactory typeFactory)
Returns the return type of theCUME_DIST
andPERCENT_RANK
aggregate functions.RelDataType
deriveRankType(RelDataTypeFactory typeFactory)
Returns the return type of theNTILE
,RANK
,DENSE_RANK
, andROW_NUMBER
aggregate functions.RelDataType
deriveSumType(RelDataTypeFactory typeFactory, RelDataType argumentType)
Returns the return type of a call to theSUM
aggregate function, inferred from its argument type.int
getDefaultPrecision(SqlTypeName typeName)
Returns default precision for this type if supported, otherwise -1 if precision is either unsupported or must be specified explicitly.java.lang.String
getLiteral(SqlTypeName typeName, boolean isPrefix)
Returns the LITERAL string for the type, either PREFIX/SUFFIX.int
getMaxNumericPrecision()
Returns the maximum precision of a NUMERIC or DECIMAL type.int
getMaxNumericScale()
Returns the maximum scale of a NUMERIC or DECIMAL type.int
getMaxPrecision(SqlTypeName typeName)
Returns the maximum precision (or length) allowed for this type, or -1 if precision/length are not applicable for this type.int
getMaxScale(SqlTypeName typeName)
Returns the maximum scale of a given type.int
getNumTypeRadix(SqlTypeName typeName)
Returns the numeric type radix, typically 2 or 10.boolean
isAutoincrement(SqlTypeName typeName)
Returns whether the type can be auto increment.boolean
isCaseSensitive(SqlTypeName typeName)
Returns whether the type is case sensitive.boolean
isSchemaCaseSensitive()
Whether two record types are considered distinct if their field names are the same but in different cases.boolean
shouldConvertRaggedUnionTypesToVarying()
Whether the least restrictive type of a number of CHAR types of different lengths should be a VARCHAR type.default boolean
shouldUseDoubleMultiplication(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2)
Returns whether a decimal multiplication should be implemented by casting arguments to double values.
-
-
-
Field Detail
-
DEFAULT
static final RelDataTypeSystem DEFAULT
Default type system.
-
-
Method Detail
-
getMaxScale
int getMaxScale(SqlTypeName typeName)
Returns the maximum scale of a given type.
-
getDefaultPrecision
int getDefaultPrecision(SqlTypeName typeName)
Returns default precision for this type if supported, otherwise -1 if precision is either unsupported or must be specified explicitly.- Returns:
- Default precision
-
getMaxPrecision
int getMaxPrecision(SqlTypeName typeName)
Returns the maximum precision (or length) allowed for this type, or -1 if precision/length are not applicable for this type.- Returns:
- Maximum allowed precision
-
getMaxNumericScale
int getMaxNumericScale()
Returns the maximum scale of a NUMERIC or DECIMAL type.
-
getMaxNumericPrecision
int getMaxNumericPrecision()
Returns the maximum precision of a NUMERIC or DECIMAL type.
-
getLiteral
java.lang.String getLiteral(SqlTypeName typeName, boolean isPrefix)
Returns the LITERAL string for the type, either PREFIX/SUFFIX.
-
isCaseSensitive
boolean isCaseSensitive(SqlTypeName typeName)
Returns whether the type is case sensitive.
-
isAutoincrement
boolean isAutoincrement(SqlTypeName typeName)
Returns whether the type can be auto increment.
-
getNumTypeRadix
int getNumTypeRadix(SqlTypeName typeName)
Returns the numeric type radix, typically 2 or 10. 0 means "not applicable".
-
deriveSumType
RelDataType deriveSumType(RelDataTypeFactory typeFactory, RelDataType argumentType)
Returns the return type of a call to theSUM
aggregate function, inferred from its argument type.
-
deriveAvgAggType
RelDataType deriveAvgAggType(RelDataTypeFactory typeFactory, RelDataType argumentType)
Returns the return type of a call to theAVG
,STDDEV
orVAR
aggregate functions, inferred from its argument type.
-
deriveCovarType
RelDataType deriveCovarType(RelDataTypeFactory typeFactory, RelDataType arg0Type, RelDataType arg1Type)
Returns the return type of a call to theCOVAR
aggregate function, inferred from its argument types.
-
deriveFractionalRankType
RelDataType deriveFractionalRankType(RelDataTypeFactory typeFactory)
Returns the return type of theCUME_DIST
andPERCENT_RANK
aggregate functions.
-
deriveRankType
RelDataType deriveRankType(RelDataTypeFactory typeFactory)
Returns the return type of theNTILE
,RANK
,DENSE_RANK
, andROW_NUMBER
aggregate 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.
-
deriveDecimalPlusType
default 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:
- the result type for a decimal addition.
- See Also:
SQL:2003 Part 2 Section 6.26
-
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
-
deriveDecimalMultiplyType
default 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:
- the result type for a decimal multiplication, or null if decimal multiplication should not be applied to the operands.
- See Also:
SQL:2003 Part 2 Section 6.26
-
deriveDecimalDivideType
default 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:
- the result type for a decimal division, or null if decimal division should not be applied to the operands.
- See Also:
SQL:2003 Part 2 Section 6.26
-
deriveDecimalModType
default 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 and requires both operands to have exact numeric types.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:
- the result type for a decimal modulus, or null if decimal modulus should not be applied to the operands.
- See Also:
SQL:2003 Part 2 Section 6.27
-
-