Class LogicalType

java.lang.Object
org.apache.flink.table.types.logical.LogicalType
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ArrayType, BigIntType, BinaryType, BooleanType, CharType, DateType, DayTimeIntervalType, DecimalType, DoubleType, FloatType, IntType, LegacyTypeInformationType, LocalZonedTimestampType, MapType, MultisetType, NullType, RawType, RowType, SmallIntType, SymbolType, TimestampType, TimeType, TinyIntType, TypeInformationRawType, UnresolvedUserDefinedType, UserDefinedType, VarBinaryType, VarCharType, YearMonthIntervalType, ZonedTimestampType

@PublicEvolving public abstract class LogicalType extends Object implements Serializable
A logical type that describes the data type of a value. It does not imply a concrete physical representation for transmission or storage but defines the boundaries between JVM-based languages and the table ecosystem.

The definition of a logical type is similar to the SQL standard's "data type" terminology but also contains information about the nullability of a value for efficient handling of scalar expressions.

Subclasses of this class define characteristics of built-in or user-defined types. Every logical type must support nullability.

Instances of this class describe the fully parameterized, immutable type with additional information such as numeric precision or expected length.

Contracts how logical types relate to other types are defined by LogicalTypeCasts and LogicalTypeMerging.

NOTE: A logical type is just a description of a type, a planner or runtime might not support every type in every logical precision yet!

See Also:
  • Constructor Details

    • LogicalType

      public LogicalType(boolean isNullable, LogicalTypeRoot typeRoot)
  • Method Details

    • isNullable

      public boolean isNullable()
      Returns whether a value of this type can be null.
    • getTypeRoot

      public LogicalTypeRoot getTypeRoot()
      Returns the root of this type. It is an essential description without additional parameters.
    • is

      public boolean is(LogicalTypeRoot typeRoot)
      Returns whether the root of the type equals to the typeRoot or not.
      Parameters:
      typeRoot - The root type to check against for equality
    • isAnyOf

      public boolean isAnyOf(LogicalTypeRoot... typeRoots)
      Returns whether the root of the type equals to at least on of the typeRoots or not.
      Parameters:
      typeRoots - The root types to check against for equality
    • isAnyOf

      public boolean isAnyOf(LogicalTypeFamily... typeFamilies)
      Returns whether the root of the type is part of at least one family of the typeFamily or not.
      Parameters:
      typeFamilies - The families to check against for equality
    • is

      public boolean is(LogicalTypeFamily family)
      Returns whether the family type of the type equals to the family or not.
      Parameters:
      family - The family type to check against for equality
    • copy

      public abstract LogicalType copy(boolean isNullable)
      Returns a deep copy of this type with possibly different nullability.
      Parameters:
      isNullable - the intended nullability of the copied type
      Returns:
      a deep copy
    • copy

      public final LogicalType copy()
      Returns a deep copy of this type. It requires an implementation of copy(boolean).
      Returns:
      a deep copy
    • asSerializableString

      public abstract String asSerializableString()
      Returns a string that fully serializes this instance. The serialized string can be used for transmitting or persisting a type.

      See LogicalTypeParser for the reverse operation.

      Returns:
      detailed string for transmission or persistence
    • asSummaryString

      public String asSummaryString()
      Returns a string that summarizes this type for printing to a console. An implementation might shorten long names or skips very specific properties.

      Use asSerializableString() for a type string that fully serializes this instance.

      Returns:
      summary string of this type for debugging purposes
    • supportsInputConversion

      public abstract boolean supportsInputConversion(Class<?> clazz)
      Returns whether an instance of the given class can be represented as a value of this logical type when entering the table ecosystem. This method helps for the interoperability between JVM-based languages and the relational type system.

      A supported conversion directly maps an input class to a logical type without loss of precision or type widening.

      For example, java.lang.Long or long can be used as input for BIGINT independent of the set nullability.

      Parameters:
      clazz - input class to be converted into this logical type
      Returns:
      flag that indicates if instances of this class can be used as input into the table ecosystem
      See Also:
    • supportsOutputConversion

      public abstract boolean supportsOutputConversion(Class<?> clazz)
      Returns whether a value of this logical type can be represented as an instance of the given class when leaving the table ecosystem. This method helps for the interoperability between JVM-based languages and the relational type system.

      A supported conversion directly maps a logical type to an output class without loss of precision or type widening.

      For example, java.lang.Long or long can be used as output for BIGINT if the type is not nullable. If the type is nullable, only java.lang.Long can represent this.

      Parameters:
      clazz - output class to be converted from this logical type
      Returns:
      flag that indicates if instances of this class can be used as output from the table ecosystem
      See Also:
    • getDefaultConversion

      public abstract Class<?> getDefaultConversion()
      Returns the default conversion class. A value of this logical type is expected to be an instance of the given class when entering or is represented as an instance of the given class when leaving the table ecosystem if no other conversion has been specified.

      For example, java.lang.Long is the default input and output for BIGINT.

      Returns:
      default class to represent values of this logical type
      See Also:
    • getChildren

      public abstract List<LogicalType> getChildren()
    • accept

      public abstract <R> R accept(LogicalTypeVisitor<R> visitor)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • withNullability

      protected String withNullability(String format, Object... params)
    • conversionSet

      protected static Set<String> conversionSet(String... elements)