Data Type Conversion

Updated at:
Copy as MD

In addition to the community Apache Flink SQL data types, Realtime Compute for Apache Flink supports implicit type conversions. This topic describes the type conversion support matrix.

Considerations

  • Realtime Compute for Apache Flink enables Legacy-Cast behavior by default, which applies to cast operations generated by both explicit and implicit type conversions.

    • Parameter description

      The table.exec.legacy-cast-behaviour parameter was introduced in community Flink 1.15. It is used in explicit and implicit type conversions to force conversions from a source data type to a target type. Note that conversions may cause precision truncation, value overflow, or null returns. For backward compatibility, the default value on the cloud is enabled, while the default value in Apache Flink is disabled.

    • About CAST

      CAST handles conversion exceptions by returning null values by default, without throwing explicit errors. In scenarios where strict exception checking is required, you can set table.exec.legacy-cast-behaviour=disabled to make jobs throw explicit errors when encountering abnormal data conversions.

    • About TRY_CAST

      TRY_CAST can be used as needed in explicit type conversions. It returns null when a conversion exception occurs, without throwing errors that cause job failures. This is equivalent to using CAST with the table.exec.legacy-cast-behaviour parameter set to enabled.

  • For null values, use explicit type conversion syntax such as cast(null as target_type), for example, cast(null as varchar). This prevents unexpected conversion results such as the "NULL" string or conversion exceptions.

Type Conversion Support Matrix

Input Type\Target Type

null

boolean

tinyint

smallint

int

bigint

decimal

float

double

interval

date

time

timestamp

[var]char

[var]binary

variant

bitmap

image

null

I

I

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

-

-

bitmap

-

-

-

-

-

-

-

-

-

-

-

-

-

E

E

-

I

-

image

-

-

-

-

-

-

-

-

-

-

-

-

-

E

E

-

-

I

The symbols are defined as follows:

  • E: Only explicit type conversion is supported.

  • I: Implicit type conversion is supported.

  • -: Type conversion is not supported.

References

For the SQL data types supported by the Apache Flink community, see Community Flink SQL data types.