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 Details

  • Method Details

    • getMaxScale

      int getMaxScale(SqlTypeName typeName)
      Returns the maximum scale allowed for this type, or RelDataType.SCALE_NOT_SPECIFIED if scale is not applicable for this type.
      Returns:
      Maximum allowed scale
    • getMinScale

      int getMinScale(SqlTypeName typeName)
      Returns the minimum scale allowed for this type, or RelDataType.SCALE_NOT_SPECIFIED if scale are not applicable for this type.
      Returns:
      Minimum allowed scale
    • getDefaultPrecision

      int getDefaultPrecision(SqlTypeName typeName)
      Returns default precision for this type if supported, otherwise RelDataType.PRECISION_NOT_SPECIFIED if precision is either unsupported or must be specified explicitly.
      Returns:
      Default precision
    • getDefaultScale

      int getDefaultScale(SqlTypeName typeName)
      Returns default scale for this type if supported, otherwise RelDataType.SCALE_NOT_SPECIFIED if scale is either unsupported or must be specified explicitly.
      Returns:
      Default scale
    • getMaxPrecision

      int getMaxPrecision(SqlTypeName typeName)
      Returns the maximum precision (or length) allowed for this type, or RelDataType.PRECISION_NOT_SPECIFIED if precision/length are not applicable for this type.
      Returns:
      Maximum allowed precision
    • getMinPrecision

      int getMinPrecision(SqlTypeName typeName)
      Returns the minimum precision (or length) allowed for this type, or RelDataType.PRECISION_NOT_SPECIFIED if precision/length are not applicable for this type.
      Returns:
      Minimum allowed precision
    • getMaxNumericScale

      @Deprecated default int getMaxNumericScale()
      Deprecated.
      Replaced by getMaxScale(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.DECIMAL values, you should do two things:

      • Override the getMaxScale(SqlTypeName) method, changing its behavior for DECIMAL;
      • Make sure that the implementation of your #getMaxNumericScale method calls getMaxScale(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.
    • getMaxNumericPrecision

      @Deprecated default int getMaxNumericPrecision()
      Deprecated.
      Replaced by getMaxScale(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.DECIMAL values, you should do two things:

      • Override the getMaxPrecision(SqlTypeName) method, changing its behavior for DECIMAL;
      • Make sure that the implementation of your #getMaxNumericPrecision method calls getMaxPrecision(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.
    • roundingMode

      RoundingMode roundingMode()
      Returns the rounding behavior for numerical operations capable of discarding precision.
    • getLiteral

      @Nullable 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 the SUM aggregate function, inferred from its argument type.
    • deriveAvgAggType

      RelDataType deriveAvgAggType(RelDataTypeFactory typeFactory, RelDataType argumentType)
      Returns the return type of a call to the AVG, STDDEV or VAR aggregate functions, inferred from its argument type.
    • deriveCovarType

      RelDataType deriveCovarType(RelDataTypeFactory typeFactory, RelDataType arg0Type, RelDataType arg1Type)
      Returns the return type of a call to the COVAR aggregate function, inferred from its argument types.
    • deriveFractionalRankType

      RelDataType deriveFractionalRankType(RelDataTypeFactory typeFactory)
      Returns the return type of the CUME_DIST and PERCENT_RANK aggregate functions.
    • deriveRankType

      RelDataType deriveRankType(RelDataTypeFactory typeFactory)
      Returns the return type of the NTILE, RANK, DENSE_RANK, and ROW_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.
    • 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 type
      type1 - Type of the first operand
      type2 - 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 type
      type1 - Type of the first operand
      type2 - 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 type
      type1 - Type of the first operand
      type2 - 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 type
      type1 - Type of the first operand
      type2 - 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

      default TimeFrameSet deriveTimeFrameSet(TimeFrameSet frameSet)
      Returns a list of supported time frames.

      The validator calls this method with TimeFrames.CORE as an argument, and the default implementation of this method returns its input, and therefore CORE is the default time frame set.

      If you wish to use a custom time frame set, create an instance of RelDataTypeSystem that overrides this method. Your method should call TimeFrameSet.builder(), will probably add all or most of the time frames in the frameSet argument, and then call TimeFrameSet.Builder.build().

      Parameters:
      frameSet - Set of built-in time frames