Enum SqlTypeName

  • All Implemented Interfaces:
    Serializable, Comparable<SqlTypeName>

    public enum SqlTypeName
    extends Enum<SqlTypeName>
    Enumeration of the type names which can be used to construct a SQL type. Rationale for this class's existence (instead of just using the standard java.sql.Type ordinals):
    • Types does not include all SQL2003 data-types;
    • SqlTypeName provides a type-safe enumeration;
    • SqlTypeName provides a place to hang extra information such as whether the type carries precision and scale.

    This class was copied over from Calcite to support variant type(CALCITE-4918). When upgrading to Calcite 1.39.0 version, please remove the entire class.

    • Field Detail

      • DEFAULT_INTERVAL_START_PRECISION

        public static final int DEFAULT_INTERVAL_START_PRECISION
        See Also:
        Constant Field Values
      • DEFAULT_INTERVAL_FRACTIONAL_SECOND_PRECISION

        public static final int DEFAULT_INTERVAL_FRACTIONAL_SECOND_PRECISION
        See Also:
        Constant Field Values
      • MIN_INTERVAL_START_PRECISION

        public static final int MIN_INTERVAL_START_PRECISION
        See Also:
        Constant Field Values
      • MIN_INTERVAL_FRACTIONAL_SECOND_PRECISION

        public static final int MIN_INTERVAL_FRACTIONAL_SECOND_PRECISION
        See Also:
        Constant Field Values
      • MAX_INTERVAL_START_PRECISION

        public static final int MAX_INTERVAL_START_PRECISION
        See Also:
        Constant Field Values
      • MAX_INTERVAL_FRACTIONAL_SECOND_PRECISION

        public static final int MAX_INTERVAL_FRACTIONAL_SECOND_PRECISION
        See Also:
        Constant Field Values
      • YEAR_INTERVAL_TYPES

        public static final Set<SqlTypeName> YEAR_INTERVAL_TYPES
      • DAY_INTERVAL_TYPES

        public static final Set<SqlTypeName> DAY_INTERVAL_TYPES
      • TIME_FRAME_TYPES

        public static final Set<SqlTypeName> TIME_FRAME_TYPES
        The possible types of a time frame argument to a function such as TIMESTAMP_DIFF.
    • Method Detail

      • values

        public static SqlTypeName[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (SqlTypeName c : SqlTypeName.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static SqlTypeName valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • get

        public static @Nullable SqlTypeName get​(String name)
        Looks up a type name from its name.
        Returns:
        Type name, or null if not found
      • allowsNoPrecNoScale

        public boolean allowsNoPrecNoScale()
      • allowsPrecNoScale

        public boolean allowsPrecNoScale()
      • allowsPrec

        public boolean allowsPrec()
      • allowsScale

        public boolean allowsScale()
      • allowsPrecScale

        public boolean allowsPrecScale​(boolean precision,
                                       boolean scale)
        Returns whether this type can be specified with a given combination of precision and scale. For example,
        • Varchar.allowsPrecScale(true, false) returns true, because the VARCHAR type allows a precision parameter, as in VARCHAR(10) .
        • Varchar.allowsPrecScale(true, true) returns true, because the VARCHAR type does not allow a precision and a scale parameter, as in VARCHAR(10, 4).
        • allowsPrecScale(false, true) returns false for every type.
        Parameters:
        precision - Whether the precision/length field is part of the type specification
        scale - Whether the scale field is part of the type specification
        Returns:
        Whether this combination of precision/scale is valid
      • isSpecial

        public boolean isSpecial()
      • getJdbcOrdinal

        public int getJdbcOrdinal()
        Returns the ordinal from Types corresponding to this SqlTypeName.
      • getDefaultScale

        public int getDefaultScale()
        Returns the default scale for this type if supported, otherwise -1 if scale is either unsupported or must be specified explicitly.
      • getFamily

        public @Nullable SqlTypeFamily getFamily()
        Gets the SqlTypeFamily containing this SqlTypeName.
        Returns:
        containing family, or null for none (SYMBOL, DISTINCT, STRUCTURED, ROW, OTHER)
      • getNameForJdbcType

        public static @Nullable SqlTypeName getNameForJdbcType​(int jdbcType)
        Gets the SqlTypeName corresponding to a JDBC type.
        Parameters:
        jdbcType - the JDBC type of interest
        Returns:
        corresponding SqlTypeName, or null if the type is not known
      • getLimit

        public @Nullable Object getLimit​(boolean sign,
                                         SqlTypeName.Limit limit,
                                         boolean beyond,
                                         int precision,
                                         int scale)
        Returns the limit of this datatype. For example,
        Datatype limits
        Datatype sign limit beyond precision scale Returns
        Integer true true false -1 -1 2147483647 (2 ^ 31 -1 = MAXINT)
        Integer true true true -1 -1 2147483648 (2 ^ 31 = MAXINT + 1)
        Integer false true false -1 -1 -2147483648 (-2 ^ 31 = MININT)
        Boolean true true false -1 -1 TRUE
        Varchar true true false 10 -1 'ZZZZZZZZZZ'
        Parameters:
        sign - If true, returns upper limit, otherwise lower limit
        limit - If true, returns value at or near to overflow; otherwise value at or near to underflow
        beyond - If true, returns the value just beyond the limit, otherwise the value at the limit
        precision - Precision, or -1 if not applicable
        scale - Scale, or -1 if not applicable
        Returns:
        Limit value
      • getMinPrecision

        public int getMinPrecision()
        Returns the minimum precision (or length) allowed for this type, or -1 if precision/length are not applicable for this type.
        Returns:
        Minimum allowed precision
      • getMinScale

        public int getMinScale()
        Returns the minimum scale (or fractional second precision in the case of intervals) allowed for this type, or -1 if precision/length are not applicable for this type.
        Returns:
        Minimum allowed scale
      • getStartUnit

        public org.apache.calcite.avatica.util.TimeUnit getStartUnit()
        Returns HOUR for HOUR TO SECOND and HOUR, SECOND for SECOND.
      • getEndUnit

        public org.apache.calcite.avatica.util.TimeUnit getEndUnit()
        Returns SECOND for both HOUR TO SECOND and SECOND.
      • isYearMonth

        public boolean isYearMonth()
      • createLiteral

        public org.apache.calcite.sql.SqlLiteral createLiteral​(Object o,
                                                               org.apache.calcite.sql.parser.SqlParserPos pos)
      • getName

        public String getName()
        Returns the name of this type.
      • getSpaceName

        public String getSpaceName()
        Returns the name of this type, with underscores converted to spaces, for example "TIMESTAMP WITH LOCAL TIME ZONE", "DATE".