Modifier and Type | Method and Description |
---|---|
static boolean |
supportsCompatibleCast(DataType sourceType,
DataType targetType)
Returns whether the source type can be compatibly cast to the target type.
|
static boolean |
supportsExplicitCast(DataType sourceType,
DataType targetType)
Returns whether the source type can be cast to the target type.
|
static boolean |
supportsImplicitCast(DataType sourceType,
DataType targetType)
Returns whether the source type can be safely cast to the target type without loosing
information.
|
public static boolean supportsImplicitCast(DataType sourceType, DataType 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(DataType sourceType, DataType 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 DataTypeFamily.PREDEFINED
family to types of the DataTypeFamily.CHARACTER_STRING
family.
public static boolean supportsCompatibleCast(DataType sourceType, DataType targetType)
If two types are compatible, they should have the same underlying data structure. For
example, CharType
and VarCharType
are both in the DataTypeFamily.CHARACTER_STRING
family, meaning they both represent a character string. But
the rest types are only compatible with themselves. For example, although IntType
and
BigIntType
are both in the DataTypeFamily.NUMERIC
family, they are not
compatible because IntType represents a 4-byte signed integer while BigIntType represents an
8-byte signed integer. Especially, two DecimalType
s are compatible only when they
have the same precision
and scale
.
Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.