Class LogicalTypeMerging


  • @Internal
    public final class LogicalTypeMerging
    extends Object
    Utilities for merging multiple LogicalType.
    • Method Detail

      • findCommonType

        public static Optional<LogicalType> findCommonType​(List<LogicalType> types)
        Returns the most common, more general LogicalType for a given set of types. If such a type exists, all given types can be casted to this more general type.

        For example: [INT, BIGINT, DECIMAL(2, 2)] would lead to DECIMAL(21, 2).

        This class aims to be compatible with the SQL standard. It is inspired by Apache Calcite's SqlTypeFactoryImpl#leastRestrictive method.

      • findDivisionDecimalType

        public static DecimalType findDivisionDecimalType​(int precision1,
                                                          int scale1,
                                                          int precision2,
                                                          int scale2)
        Finds the result type of a decimal division operation.
      • findModuloDecimalType

        public static DecimalType findModuloDecimalType​(int precision1,
                                                        int scale1,
                                                        int precision2,
                                                        int scale2)
        Finds the result type of a decimal modulo operation.
      • findMultiplicationDecimalType

        public static DecimalType findMultiplicationDecimalType​(int precision1,
                                                                int scale1,
                                                                int precision2,
                                                                int scale2)
        Finds the result type of a decimal multiplication operation.
      • findAdditionDecimalType

        public static DecimalType findAdditionDecimalType​(int precision1,
                                                          int scale1,
                                                          int precision2,
                                                          int scale2)
        Finds the result type of a decimal addition operation.
      • findRoundDecimalType

        public static DecimalType findRoundDecimalType​(int precision,
                                                       int scale,
                                                       int round)
        Finds the result type of a decimal rounding operation.
      • findAvgAggType

        public static LogicalType findAvgAggType​(LogicalType argType)
        Finds the result type of a decimal average aggregation.
      • findSumAggType

        public static LogicalType findSumAggType​(LogicalType argType)
        Finds the result type of a decimal sum aggregation.