@PublicEvolving public abstract class LogicalType extends Object implements Serializable
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!
Constructor and Description |
---|
LogicalType(boolean isNullable,
LogicalTypeRoot typeRoot) |
Modifier and Type | Method and 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 the
family or not. |
boolean |
is(LogicalTypeRoot typeRoot)
Returns whether the root of the type equals to the
typeRoot or not. |
boolean |
isAnyOf(LogicalTypeFamily... typeFamilies)
Returns whether the root of the type is part of at least one family of the
typeFamily
or not. |
boolean |
isAnyOf(LogicalTypeRoot... typeRoots)
Returns whether the root of the type equals to at least on of the
typeRoots or not. |
boolean |
isNullable()
Returns whether a value of this type can be
null . |
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) |
public LogicalType(boolean isNullable, LogicalTypeRoot typeRoot)
public boolean isNullable()
null
.public LogicalTypeRoot getTypeRoot()
public boolean is(LogicalTypeRoot typeRoot)
typeRoot
or not.typeRoot
- The root type to check against for equalitypublic boolean isAnyOf(LogicalTypeRoot... typeRoots)
typeRoots
or not.typeRoots
- The root types to check against for equalitypublic boolean isAnyOf(LogicalTypeFamily... typeFamilies)
typeFamily
or not.typeFamilies
- The families to check against for equalitypublic boolean is(LogicalTypeFamily family)
family
or not.family
- The family type to check against for equalitypublic abstract LogicalType copy(boolean isNullable)
isNullable
- the intended nullability of the copied typepublic final LogicalType copy()
copy(boolean)
.public abstract String asSerializableString()
See LogicalTypeParser
for the reverse operation.
public String asSummaryString()
Use asSerializableString()
for a type string that fully serializes this instance.
public abstract boolean supportsInputConversion(Class<?> clazz)
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.
clazz
- input class to be converted into this logical typegetDefaultConversion()
public abstract boolean supportsOutputConversion(Class<?> clazz)
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.
clazz
- output class to be converted from this logical typegetDefaultConversion()
public abstract Class<?> getDefaultConversion()
For example, java.lang.Long
is the default input and output for BIGINT
.
supportsInputConversion(Class)
,
supportsOutputConversion(Class)
public abstract List<LogicalType> getChildren()
public abstract <R> R accept(LogicalTypeVisitor<R> visitor)
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.