Class Types

java.lang.Object
org.apache.drill.common.types.Types

public class Types extends Object
  • Field Details

  • Constructor Details

    • Types

      public Types()
  • Method Details

    • isUnion

      public static boolean isUnion(TypeProtos.MajorType toType)
    • isComplex

      public static boolean isComplex(TypeProtos.MajorType type)
    • isRepeated

      public static boolean isRepeated(TypeProtos.MajorType type)
    • isNumericType

      public static boolean isNumericType(TypeProtos.MajorType type)
    • isNumericType

      public static boolean isNumericType(TypeProtos.MinorType type)
    • isDateTimeType

      public static boolean isDateTimeType(TypeProtos.MajorType type)
    • isDateTimeType

      public static boolean isDateTimeType(TypeProtos.MinorType type)
    • isIntervalType

      public static boolean isIntervalType(TypeProtos.MajorType type)
    • isIntervalType

      public static boolean isIntervalType(TypeProtos.MinorType type)
    • areDecimalTypes

      public static boolean areDecimalTypes(TypeProtos.MinorType... types)
      Returns true if all specified types are decimal data types.
      Parameters:
      types - types to check
      Returns:
      true if all specified types are decimal data type.
    • isDecimalType

      public static boolean isDecimalType(TypeProtos.MajorType type)
      Returns true if specified type is decimal data type.
      Parameters:
      type - type to check
      Returns:
      true if specified type is decimal data type.
    • isDecimalType

      public static boolean isDecimalType(TypeProtos.MinorType minorType)
      Returns true if specified type is decimal data type.
      Parameters:
      minorType - type to check
      Returns:
      true if specified type is decimal data type.
    • getSqlTypeName

      public static String getSqlTypeName(TypeProtos.MajorType type)
      Gets SQL data type name for given Drill RPC-/protobuf-level data type.
      Returns:
      canonical keyword sequence for SQL data type (leading keywords in corresponding <data type>; what INFORMATION_SCHEMA.COLUMNS.TYPE_NAME would list)
    • getBaseSqlTypeName

      public static String getBaseSqlTypeName(TypeProtos.MajorType type)
    • getExtendedSqlTypeName

      public static String getExtendedSqlTypeName(TypeProtos.MajorType type)
      Extend decimal type with precision and scale.
      Parameters:
      type - major type
      Returns:
      type name augmented with precision and scale, if type is a decimal
    • getSqlModeName

      public static String getSqlModeName(TypeProtos.MajorType type)
    • getJdbcTypeCode

      public static int getJdbcTypeCode(String sqlTypeName)
      Gets JDBC type code for given SQL data type name.
    • isJdbcSignedType

      public static boolean isJdbcSignedType(TypeProtos.MajorType type)
      Reports whether given RPC-level type is a signed type (per semantics of ResultSetMetaData.isSigned(int)).
    • getJdbcDisplaySize

      public static int getJdbcDisplaySize(TypeProtos.MajorType type)
    • usesHolderForGet

      public static boolean usesHolderForGet(TypeProtos.MajorType type)
    • isFixedWidthType

      public static boolean isFixedWidthType(TypeProtos.MajorType type)
    • isFixedWidthType

      public static boolean isFixedWidthType(TypeProtos.MinorType type)
    • isVarWidthType

      public static boolean isVarWidthType(TypeProtos.MinorType type)
    • isScalarStringType

      public static boolean isScalarStringType(TypeProtos.MajorType type)
      Checks if given major type is string scalar type.
      Parameters:
      type - major type
      Returns:
      true if given major type is scalar string, false otherwise
    • softEquals

      public static boolean softEquals(TypeProtos.MajorType a, TypeProtos.MajorType b, boolean allowNullSwap)
    • isUntypedNull

      public static boolean isUntypedNull(TypeProtos.MajorType type)
    • withMode

      public static TypeProtos.MajorType withMode(TypeProtos.MinorType type, TypeProtos.DataMode mode)
    • withPrecision

      public static TypeProtos.MajorType withPrecision(TypeProtos.MinorType type, TypeProtos.DataMode mode, int precision)
      Builds major type using given minor type, data mode and precision.
      Parameters:
      type - minor type
      mode - data mode
      precision - precision value
      Returns:
      major type
    • withPrecisionAndScale

      public static TypeProtos.MajorType withPrecisionAndScale(TypeProtos.MinorType type, TypeProtos.DataMode mode, int precision, int scale)
    • required

      public static TypeProtos.MajorType required(TypeProtos.MinorType type)
    • repeated

      public static TypeProtos.MajorType repeated(TypeProtos.MinorType type)
    • optional

      public static TypeProtos.MajorType optional(TypeProtos.MinorType type)
    • overrideMode

      public static TypeProtos.MajorType overrideMode(TypeProtos.MajorType originalMajorType, TypeProtos.DataMode overrideMode)
    • getMajorTypeFromName

      public static TypeProtos.MajorType getMajorTypeFromName(String typeName)
    • getMinorTypeFromName

      public static TypeProtos.MinorType getMinorTypeFromName(String typeName)
    • getMajorTypeFromName

      public static TypeProtos.MajorType getMajorTypeFromName(String typeName, TypeProtos.DataMode mode)
    • getNameOfMinorType

      public static String getNameOfMinorType(TypeProtos.MinorType type)
    • toString

      public static String toString(TypeProtos.MajorType type)
    • getPrecision

      public static int getPrecision(TypeProtos.MajorType majorType)
      Get the precision of given type.
      Parameters:
      majorType - major type
      Returns:
      precision value
    • getScale

      public static int getScale(TypeProtos.MajorType majorType)
      Get the scale of given type.
      Parameters:
      majorType - major type
      Returns:
      scale value
    • isSortable

      public static boolean isSortable(TypeProtos.MinorType type)
      Checks if the given type column can be used in ORDER BY clause.
      Parameters:
      type - minor type
      Returns:
      true if type can be used in ORDER BY clause
    • calculateTypePrecisionAndScale

      public static TypeProtos.MajorType.Builder calculateTypePrecisionAndScale(TypeProtos.MajorType leftType, TypeProtos.MajorType rightType, TypeProtos.MajorType.Builder typeBuilder)
      Sets max precision from both types if these types are string scalar types. Sets max precision and scale from both types if these types are decimal types. Both types should be of the same minor type.
      Parameters:
      leftType - type from left side
      rightType - type from right side
      typeBuilder - type builder
      Returns:
      type builder
    • isSameType

      public static boolean isSameType(TypeProtos.MajorType type1, TypeProtos.MajorType type2)
      Check if two "core" types are the same, ignoring subtypes and children. Primarily for non-complex types.
      Parameters:
      type1 - first type
      type2 - second type
      Returns:
      true if the two types have the same minor type, mode, precision and scale
    • isSameTypeAndMode

      public static boolean isSameTypeAndMode(TypeProtos.MajorType first, TypeProtos.MajorType second)
      Check if two "core" types have the same minor type and data mode, ignoring subtypes and children. Primarily for non-complex types.
      Parameters:
      first - first type to check
      second - second type to check
      Returns:
      true if the two types have the same minor type and mode, false otherwise
    • isEquivalent

      public static boolean isEquivalent(TypeProtos.MajorType type1, TypeProtos.MajorType type2)
      Requires full type equality, including fields such as precision and scale. But, unset fields are equivalent to 0. Can't use the protobuf-provided isEquals() which treats set and unset fields as different.
    • typeKey

      public static String typeKey(TypeProtos.MinorType type)
      The union vector is a map of types. The following method provides the standard name to use in the type map. It replaces the many ad-hoc appearances of this code in each reference to the map.
      Parameters:
      type - Drill data type
      Returns:
      string key to use for this type in a union vector type map
    • maxPrecision

      public static int maxPrecision(TypeProtos.MinorType type)
    • isNullable

      public static boolean isNullable(TypeProtos.MajorType type)