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
andLogicalTypeMerging
.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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LogicalType(boolean isNullable, LogicalTypeRoot typeRoot)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract <R> R
accept(LogicalTypeVisitor<R> visitor)
abstract String
asSerializableString()
Returns a string that fully serializes this instance.String
asSummaryString()
Returns a string that summarizes this type for printing to a console.protected static Set<String>
conversionSet(String... elements)
LogicalType
copy()
Returns a deep copy of this type.abstract LogicalType
copy(boolean isNullable)
Returns a deep copy of this type with possibly different nullability.boolean
equals(Object o)
abstract List<LogicalType>
getChildren()
abstract Class<?>
getDefaultConversion()
Returns the default conversion class.LogicalTypeRoot
getTypeRoot()
Returns the root of this type.int
hashCode()
boolean
is(LogicalTypeFamily family)
Returns whether the family type of the type equals to thefamily
or not.boolean
is(LogicalTypeRoot typeRoot)
Returns whether the root of the type equals to thetypeRoot
or not.boolean
isAnyOf(LogicalTypeFamily... typeFamilies)
Returns whether the root of the type is part of at least one family of thetypeFamily
or not.boolean
isAnyOf(LogicalTypeRoot... typeRoots)
Returns whether the root of the type equals to at least on of thetypeRoots
or not.boolean
isNullable()
Returns whether a value of this type can benull
.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.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.String
toString()
protected String
withNullability(String format, Object... params)
-
-
-
Constructor Detail
-
LogicalType
public LogicalType(boolean isNullable, LogicalTypeRoot typeRoot)
-
-
Method Detail
-
isNullable
public boolean isNullable()
Returns whether a value of this type can benull
.
-
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 thetypeRoot
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 thetypeRoots
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 thetypeFamily
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 thefamily
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 ofcopy(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
orlong
can be used as input forBIGINT
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:
getDefaultConversion()
-
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
orlong
can be used as output forBIGINT
if the type is not nullable. If the type is nullable, onlyjava.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()
-
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 forBIGINT
.- Returns:
- default class to represent values of this logical type
- See Also:
supportsInputConversion(Class)
,supportsOutputConversion(Class)
-
getChildren
public abstract List<LogicalType> getChildren()
-
accept
public abstract <R> R accept(LogicalTypeVisitor<R> visitor)
-
-