In addition to explicit casting pairs supported by Apache Flink, Realtime Compute for Apache Flink also supports implicit type conversion. This topic describes the data type conversion matrix.
Usage notes
Realtime Compute for Apache Flink implements legacy casting by default for explicit and implicit type conversions. Take note of the following:
Parameter details
The
table.exec.legacy-cast-behaviourparameter, introduced in Apache Flink 1.15, dictates how explicit and implicit type conversions are handled. When enabled, it forces a cast from a source type to a target type, which may result in precision loss, value overflow, or null returns. Default value:enabledfor Realtime Compute for Apache Flink, anddisabledfor Apache Flink.CAST
By default,
CASTreturns null when a conversion error occurs and does not throw an explicit error. In scenarios that require strict checks for abnormal values, settable.exec.legacy-cast-behaviour=disabledto throw an explicit error when a data conversion error is encountered.TRY_CAST
Use
TRY_CASTfor explicit type conversions. It returns null when a conversion error occurs and does not fail the job. This is equivalent to usingCASTwithtable.exec.legacy-cast-behaviourset toenabled.
Use explicit conversion
cast(null as target_type)to handle null values and prevents unexpected results, such as obtaining "NULL" strings or triggering exceptions. For example, to convert a null value to a varchar type, the appropriate syntax iscast(null as varchar).
Data type conversion matrix
Input\Target | null | boolean | tinyint | smallint | int | bigint | decimal | float | double | interval | date | time | timestamp | [var]char | [var]binary | variant |
null | I | I | I | I | I | I | I | I | I | I | I | I | I | I | I | I |
boolean | - | I | E | E | E | E | E | E | E | - | - | - | - | I | - | E |
tinyint | - | E | I | I | I | I | I | I | I | E | - | - | E | I | - | E |
smallint | - | E | I | I | I | I | I | I | I | E | - | - | E | I | - | E |
int | - | E | I | I | I | I | I | I | I | E | - | - | E | I | - | E |
bigint | - | E | I | I | I | I | I | I | I | E | - | - | E | I | - | E |
decimal | - | E | I | I | I | I | I | I | I | E | - | - | E | I | - | E |
float | - | E | I | I | I | I | I | I | I | - | - | - | E | I | - | E |
double | - | E | I | I | I | I | I | I | I | - | - | - | E | I | - | E |
interval | - | - | E | E | E | E | E | - | - | I | - | - | - | E | - | E |
date | - | - | - | - | - | - | - | - | - | - | I | - | I | I | - | E |
time | - | - | - | - | - | - | - | - | - | - | - | I | E | I | - | E |
timestamp | - | - | E | E | E | E | E | E | E | - | I | E | I | I | - | E |
[var]char | - | E | I | I | I | I | I | I | I | I | I | I | I | I | I | E |
[var]binary | - | - | - | - | - | - | - | - | - | - | E | E | E | I | I | E |
variant | - | E | E | E | E | E | E | E | E | E | E | E | E | E | E | I |
Notes:
E: only explicit conversion is supported.
I: implicit conversion is supported.
-: data type conversion is not supported.
Reference
For information about casting pairs supported by Apache Flink, see Data types.