@Internal public final class LogicalTypeCasts extends Object
LogicalType
.
This class aims to be compatible with the SQL standard. It is inspired by Apache Calcite's
SqlTypeUtil#canCastFrom
method.
Casts can be performed in two ways: implicit or explicit.
Explicit casts correspond to the SQL cast specification and represent the logic behind a
CAST(sourceType AS targetType)
operation. For example, it allows for converting most types
of the LogicalTypeFamily.PREDEFINED
family to types of the LogicalTypeFamily.CHARACTER_STRING
family.
Implicit casts are used for safe type widening and type generalization (finding a common supertype
for a set of types) without loss of information. Implicit casts are similar to the Java semantics
(e.g. this is not possible: int x = (String) z
).
Conversions that are defined by the LogicalType
(e.g. interpreting a DateType
as integer value) are not considered here. They are an internal bridging feature that is not
standard compliant. If at all, CONVERT
methods should make such conversions available.
Modifier and Type | Method and Description |
---|---|
static boolean |
supportsExplicitCast(LogicalType sourceType,
LogicalType targetType)
Returns whether the source type can be casted to the target type.
|
static boolean |
supportsImplicitCast(LogicalType sourceType,
LogicalType targetType)
Returns whether the source type can be safely casted to the target type without loosing information.
|
public static boolean supportsImplicitCast(LogicalType sourceType, LogicalType targetType)
Implicit casts are used for type widening and type generalization (finding a common supertype
for a set of types). Implicit casts are similar to the Java semantics (e.g. this is not possible:
int x = (String) z
).
public static boolean supportsExplicitCast(LogicalType sourceType, LogicalType targetType)
Explicit casts correspond to the SQL cast specification and represent the logic behind a
CAST(sourceType AS targetType)
operation. For example, it allows for converting most types
of the LogicalTypeFamily.PREDEFINED
family to types of the LogicalTypeFamily.CHARACTER_STRING
family.
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.