Data Types in Confluent Cloud for Apache Flink

Confluent Cloud for Apache Flink® has a rich set of native data types that you can use in SQL statements and queries. The query planner supports the Flink SQL types that are described in this topic.

The following table shows the mapping of Flink SQL types to Java and Python types. For the mapping of Flink SQL types to JSON Schema, Protobuf, and Avro types, see Data Type Mappings for serialization.

Flink SQL type

Java type

Python type

ARRAY

t[]

numpy.ndarray, list[t]

BIGINT

long

int

BINARY

byte[]

bytes, bytearray

BOOLEAN

boolean

bool(<expr>)

BYTES / VARBINARY

byte[]

bytes, bytearray

CHAR

String

str

DATE

java.time.LocalDate

datetime.date

DECIMAL

java.math.BigDecimal

decimal.Decimal

DOUBLE

double

float

FLOAT

float

float

INT

long

int

INTERVAL DAY TO SECOND

java.time.Duration

datetime.timedelta

INTERVAL YEAR TO MONTH

java.time.Period

dateutil.relativedelta

MAP

java.util.Map<kt, vt>

dict[kt, vt]

MULTISET

java.util.Map<t, Integer>

dict[t, int]

NULL

java.lang.Object

object

ROW

org.apache.flink.types.Row

pyflink.table.types.RowType

SMALLINT

short

int

TIME

java.time.LocalTime

datetime.time

TIMESTAMP

java.time.LocalDateTime

datetime.datetime

TIMESTAMP_LTZ

java.time.Instant

datetime.datetime

TINYINT

byte

bytes, bytearray

VARCHAR / STRING

String

str

Data type definition

A data type describes the logical type of a value in a SQL table. You use data types to declare the input and output types of an operation.

The Flink data types are similar to the SQL standard data type terminology, but for efficient handling of scalar expressions, they also contain information about the nullability of a value.

These are examples of SQL data types:

INT
INT NOT NULL
INTERVAL DAY TO SECOND(3)
ROW<fieldOne ARRAY<BOOLEAN>, fieldTwo TIMESTAMP(3)>

The following sections list all pre-defined data types in Flink SQL.

Character strings

CHAR

Represents a fixed-length character string.

Syntax

CHAR
CHAR(n)

Example

CREATE TABLE test_sql_char (val CHAR(3));
INSERT INTO test_sql_char VALUES ('ABCD');

-- returns 'ABC'
SELECT * FROM test_sql_char;

Declare this type by using CHAR(n), where n is the number of code points. n must have a value between 1 and 2,147,483,647 (both inclusive). If no length is specified, n is equal to 1.

CHAR(0) is not supported for CAST or persistence in catalogs, but it exists in protocols.

Syntax

char

Example

char charValue1 = 'A';
char charValue2 = 65;

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.String

Default

byte[]

Assumes UTF-8 encoding

org.apache.flink.table.data.StringData

Internal data structure

Not supported. Python has no char type, so a single character is treated as a string with length 1.

Formats

The following table shows examples of the CHAR type in different formats.

JSON for data type

{"type":"CHAR","nullable":true,"length":8}

CLI/UI format

CHAR(8)

JSON for payload

"Example string"

CLI/UI format for payload

Example string

VARCHAR / STRING

Represents a variable-length character string.

Syntax

VARCHAR
VARCHAR(n)

STRING

Example

CREATE TABLE test_sql_varchar (val VARCHAR(3));
INSERT INTO test_sql_varchar VALUES ('ABCDEF');

-- returns 'ABC'
SELECT * FROM test_sql_varchar;

Declare this type by using VARCHAR(n), where n is the maximum number of code points. n must have a value between 1 and 2,147,483,647 (both inclusive). If no length is specified, n is equal to 1.

STRING is equivalent to VARCHAR(2147483647).

VARCHAR(0) is not supported for CAST or persistence in catalogs, but it exists in protocols.

Syntax

string

Example

string stringValue = "Hello World";

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.String

Default

byte[]

Assumes UTF-8 encoding

org.apache.flink.table.data.StringData

Internal data structure

Examples

stringValue = "Hello World"
number = 123
stringValue1 = str(number)  # Converts integer to string

Formats

The following table shows examples of the VARCHAR type in different formats.

JSON for data type

{"type":"VARCHAR","nullable":true,"length":8}

CLI/UI format

VARCHAR(800)

JSON for payload

"Example string"

CLI/UI format for payload

Example string

Binary strings

BINARY

Represents a fixed-length binary string, or a sequence of bytes.

Syntax

BINARY
BINARY(n)

Example

CREATE TABLE test_sql_binary (val BINARY(3));
INSERT INTO test_sql_binary VALUES (X'7f0203');

-- returns x'7f0203'
SELECT * FROM test_sql_binary;

Declare this type by using BINARY(n), where n is the number of bytes. n must have a value between 1 and 2,147,483,647 (both inclusive). If no length is specified, n is equal to 1.

The string representation is hexadecimal format.

BINARY(0) is not supported for CAST or persistence in catalogs, but it exists in protocols.

Syntax

byte[]

Example

byte[] binaryValue = {0x7f, 0x02, 0x03};

Bridging to JVM types

Java Type

Input

Output

Notes

byte[]

Default

Example

data = bytes([65, 66, 67])

Formats

The following table shows examples of the BINARY type in different formats.

JSON for data type

{"type":"BINARY","nullable":true,"length":1}

CLI/UI format

BINARY(3)

JSON for payload

"x'7f0203'"

CLI/UI format for payload

x'7f0203'

BYTES / VARBINARY

Represents a variable-length binary string (=a sequence of bytes).

Syntax

BYTES
VARBINARY
VARBINARY(n)

Example

CREATE TABLE test_sql_bytes (val VARBINARY(3));
INSERT INTO test_sql_bytes VALUES (X'7f0203040506');

-- returns x'7f0203'
SELECT * FROM test_sql_bytes;

Declare this type by using VARBINARY(n) where n is the maximum number of bytes. n must have a value between 1 and 2,147,483,647 (both inclusive). If no length is specified, n is equal to 1.

BYTES is equivalent to VARBINARY(2147483647).

VARCHAR(0) is not supported for CAST or persistence in catalogs, but it exists in protocols.

Syntax

byte[]

Example

byte[] binaryValue = {0x7f, 0x02, 0x03};

Bridging to JVM types

Java Type

Input

Output

Notes

byte[]

Default

Syntax

bytes

Example

bytesValue = bytes([65, 66, 67])

Formats

The following table shows examples of the VARBINARY type in different formats.

JSON for data type

{"type":"VARBINARY","nullable":true,"length":1}

CLI/UI format

VARBINARY(800)

JSON for payload

"x'7f0203'"

CLI/UI format for payload

x'7f0203'

Exact numerics

BIGINT

Represents an 8-byte signed integer with values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

Syntax

BIGINT

Example

CREATE TABLE test_sql_bigint (val BIGINT);
INSERT INTO test_sql_bigint VALUES (1234567890123456789);

-- returns 1234567890123456800
SELECT * FROM test_sql_bigint;

Syntax

long

Example

long longValue = 1234567890123456789;

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.Long

Default

long

(✓)

Output only if type is not nullable

Syntax

int

Example

longValue = 1234567890123456789

Formats

The following table shows examples of the BIGINT type in different formats.

JSON for data type

{"type":"BIGINT","nullable":true}

CLI/UI format

BIGINT

JSON for payload

"23"

CLI/UI format for payload

23

DECIMAL

Represents a decimal number with fixed precision and scale.

Syntax

DEC
DEC(p)
DEC(p, s)

DECIMAL
DECIMAL(p)
DECIMAL(p, s)

NUMERIC
NUMERIC(p)
NUMERIC(p, s)

Example

CREATE TABLE test_sql_decimal (val DECIMAL(5, 3));
INSERT INTO test_sql_decimal VALUES (12.123), (123.12345);

-- returns 12.123, NULL
SELECT * FROM test_sql_decimal;

Declare this type by using DECIMAL(p, s) where p is the number of digits in a number (precision) and s is the number of digits to the right of the decimal point in a number (scale).

p must have a value between 1 and 38 (both inclusive). The default value for p is 10.

s must have a value between 0 and p (both inclusive). The default value for s is 0.

The right side is padded with 0.

The left side must be padded with spaces, like all other values.

NUMERIC(p, s) and DEC(p, s) are synonyms for this type.

Syntax

BigDecimal

Example

BigDecimal decimalValue = new BigDecimal("12.123");

Bridging to JVM types

Java Type

Input

Output

Notes

java.math.BigDecimal

Default

org.apache.flink.table.data.DecimalData

Internal data structure

Syntax

decimal.Decimal

Example

decimalValue = decimal.Decimal("12.123")

Formats

The following table shows examples of the DECIMAL type in different formats.

JSON for data type

{"type":"DECIMAL","nullable":true,"precision":5,"scale":3}

CLI/UI format

DECIMAL(5, 3)

JSON for payload

"12.123"

CLI/UI format for payload

12.123

INT

Represents a 4-byte signed integer with values from -2,147,483,648 to 2,147,483,647.

Syntax

INT
INTEGER

INTEGER is a synonym for this type.

Example

CREATE TABLE test_sql_int (val INT);
INSERT INTO test_sql_int VALUES (1234567890);

-- returns 1234567890
SELECT * FROM test_sql_int;

Syntax

int

Example

int intValue = 1234567890;

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.Integer

Default

long

(✓)

Output only if type is not nullable

Syntax

int

Example

intValue = 1234567890

Formats

The following table shows examples of the INT type in different formats.

JSON for data type

{"type":"INT","nullable":true}

CLI/UI format

INT

JSON for payload

"23"

CLI/UI format for payload

23

SMALLINT

Represents a 2-byte signed integer with values from -32,768 to 32,767.

Syntax

SMALLINT

Example

CREATE TABLE test_sql_smallint (val SMALLINT);
INSERT INTO test_sql_smallint VALUES (CAST(1234567890 AS SMALLINT));

-- returns 722
SELECT * FROM test_sql_smallint;

Syntax

short

Example

short shortValue = 1234567890;

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.Short

Default

short

(✓ )

Output only if type is not nullable

Syntax

int

Example

shortValue = 1234567890

Formats

The following table shows examples of the SMALLINT type in different formats.

JSON for data type

{"type":"SMALLINT","nullable":true}

CLI/UI format

SMALLINT

JSON for payload

"23"

CLI/UI format for payload

23

TINYINT

Represents a 1-byte signed integer with values from -128 to 127.

Syntax

TINYINT

Example

CREATE TABLE test_sql_tinyint (val TINYINT);
INSERT INTO test_sql_tinyint VALUES (CAST(1234567890 AS TINYINT));

-- returns -46
SELECT * FROM test_sql_tinyint;

Syntax

byte

Example

byte byteValue = 123;

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.Byte

Default

byte

(✓)

Output only if type is not nullable

Syntax

byte

Example

byteValue = 123

Formats

The following table shows examples of the TINYINT type in different formats.

JSON for data type

{"type":"TINYINT","nullable":true}

CLI/UI format

TINYINT

JSON for payload

"23"

CLI/UI format for payload

23

Approximate numerics

DOUBLE

Represents an 8-byte double precision floating point number.

Syntax

DOUBLE

DOUBLE PRECISION

Example

CREATE TABLE test_sql_double (val DOUBLE);
INSERT INTO test_sql_double VALUES (1.1111112120000001E7);

-- returns 11111112.120000001
SELECT * FROM test_sql_double;

DOUBLE PRECISION is a synonym for this type.

Syntax

double

Example

double doubleValue = 1.1111112120000001E7;

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.Double

Default

double

(✓)

Output only if type is not nullable

Syntax

float

Example

doubleValue = 1.1111112120000001E7

Formats

The following table shows examples of the DOUBLE type in different formats.

JSON for data type

{"type":"DOUBLE","nullable":true}

CLI/UI format

DOUBLE

JSON for payload

"1.1111112120000001E7"

CLI/UI format for payload

1.1111112120000001E7

FLOAT

Represents a 4-byte single precision floating point number.

Syntax

FLOAT

Example

CREATE TABLE test_sql_float (val FLOAT);
INSERT INTO test_sql_float VALUES (1.1111112);

-- returns 1.1111112
SELECT * FROM test_sql_float;

Compared to the SQL standard, this type doesn’t take parameters.

Syntax

float

Example

float floatValue = 1.1111112;

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.Float

Default

float

(✓)

Output only if type is not nullable

Syntax

float

Example

floatValue = 1.1111112

Formats

The following table shows examples of the FLOAT type in different formats.

JSON for data type

{"type":"FLOAT","nullable":true}

CLI/UI format

FLOAT

JSON for payload

"1.1111112E7"

CLI/UI format for payload

1.1111112E7

Date and time

DATE

Represents a date consisting of year-month-day with values ranging from 0000-01-01 to 9999-12-31.

Syntax

DATE

Example

CREATE TABLE test_sql_date (val DATE);
INSERT INTO test_sql_date VALUES (CAST('2023-04-06' AS DATE));

-- returns 2023-04-06
SELECT * FROM test_sql_date;

Compared to the SQL standard, the range starts at year 0000.

Syntax

date

Example

date dateValue = date(2023, 4, 6);

Bridging to JVM types

Java Type

Input

Output

Notes

java.time.LocalDate

Default

java.sql.Date

java.lang.Integer

Describes the number of days since Unix epoch

int

(✓)

Describes the number of days since Unix epoch. Output only if type is not nullable.

Syntax

date

Example

dateValue = date(2023, 4, 6)

Formats

The following table shows examples of the DATE type in different formats.

JSON for data type

{"type":"DATE","nullable":true}

CLI/UI format

DATE

JSON for payload

"2023-04-06"

CLI/UI format for payload

2023-04-06

INTERVAL DAY TO SECOND

Data type for a group of day-time interval types.

Syntax

INTERVAL DAY
INTERVAL DAY(p1)
INTERVAL DAY(p1) TO HOUR
INTERVAL DAY(p1) TO MINUTE
INTERVAL DAY(p1) TO SECOND(p2)
INTERVAL HOUR
INTERVAL HOUR TO MINUTE
INTERVAL HOUR TO SECOND(p2)
INTERVAL MINUTE
INTERVAL MINUTE TO SECOND(p2)
INTERVAL SECOND
INTERVAL SECOND(p2)

Example

CREATE TABLE test_sql_interval_d_to_s (val INTERVAL DAY(2) TO SECOND(3));
INSERT INTO test_sql_interval_d_to_s VALUES (INTERVAL '2 07:33:20.000' DAY TO SECOND);

-- returns +2 07:33:20.000
SELECT * FROM test_sql_interval_d_to_s;

Declare this type by using the above combinations, where p1 is the number of digits of days (day precision) and p2 is the number of digits of fractional seconds (fractional precision).

p1 must have a value between 1 and 6 (both inclusive). If no p1 is specified, it is equal to 2 by default.

p2 must have a value between 0 and 9 (both inclusive). If no p2 is specified, it is equal to 6 by default.

The type must be parameterized to one of these resolutions with up to nanosecond precision:

  • Interval of days

  • Interval of days to hours

  • Interval of days to minutes

  • Interval of days to seconds

  • Interval of hours

  • Interval of hours to minutes

  • Interval of hours to seconds

  • Interval of minutes

  • Interval of minutes to seconds

  • Interval of seconds

An interval of day-time consists of +days hours:months:seconds.fractional with values ranging from -999999 23:59:59.999999999 to +999999 23:59:59.999999999. The value representation is the same for all types of resolutions. For example, an interval of seconds of 70 is always represented in an interval-of-days-to-seconds format (with default precisions): +00 00:01:10.000000.

Formatting intervals are tricky, because they have different resolutions:

  • DAY

  • DAY_TO_HOUR

  • DAY_TO_MINUTE

  • DAY_TO_SECOND

  • HOUR

  • HOUR_TO_MINUTE

  • HOUR_TO_SECOND

  • MINUTE

  • MINUTE_TO_SECOND

  • SECOND

Depending on the resolution, use:

INTERVAL DAY(1)
INTERVAL DAY(1) TO HOUR
INTERVAL DAY(1) TO MINUTE
INTERVAL DAY(1) TO SECOND(3)
INTERVAL HOUR
INTERVAL HOUR TO MINUTE
INTERVAL HOUR TO SECOND(3)
INTERVAL MINUTE
INTERVAL MINUTE TO SECOND(3)
INTERVAL SECOND(3)

Syntax

Duration

DataTypes.INTERVAL

Example

// HH:MM:SS = 2:07:33
Duration intervalValue = Duration.ofSeconds(2 * 3600 + 7 * 60 + 33);

Table API examples

import static org.apache.flink.table.api.DataTypes.*;

// Single field intervals
DataType intervalDay = INTERVAL(DAY());
DataType intervalDayWithParam = INTERVAL(DAY(p1));
DataType intervalDayToHour = INTERVAL(DAY(p1), HOUR());
DataType intervalDayToMinute = INTERVAL(DAY(p1), MINUTE());
DataType intervalDayToSecond = INTERVAL(DAY(p1), SECOND(p2));

// Hour-based intervals
DataType intervalHour = INTERVAL(HOUR());
DataType intervalHourToMinute = INTERVAL(HOUR(), MINUTE());
DataType intervalHourToSecond = INTERVAL(HOUR(), SECOND(p2));

// Minute-based intervals
DataType intervalMinute = INTERVAL(MINUTE());
DataType intervalMinuteToSecond = INTERVAL(MINUTE(), SECOND(p2));

// Second-based intervals
DataType intervalSecond = INTERVAL(SECOND());
DataType intervalSecondWithParam = INTERVAL(SECOND(p2));

Bridging to JVM types

Java Type

Input

Output

Notes

java.time.Duration

Default

java.lang.Long

Describes the number of milliseconds

long

(✓)

Describes the number of milliseconds. Output only if type is not nullable.

Syntax

from pyflink.table.types import DataTypes

interval_day = DataTypes.INTERVAL(DataTypes.DAY())

Examples

from pyflink.table.types import DataTypes

# Single field intervals
interval_day = DataTypes.INTERVAL(DataTypes.DAY())
interval_day_with_param = DataTypes.INTERVAL(DataTypes.DAY(p1))
interval_day_to_hour = DataTypes.INTERVAL(DataTypes.DAY(p1), DataTypes.HOUR())
interval_day_to_minute = DataTypes.INTERVAL(DataTypes.DAY(p1), DataTypes.MINUTE())
interval_day_to_second = DataTypes.INTERVAL(DataTypes.DAY(p1), DataTypes.SECOND(p2))

# Hour-based intervals
interval_hour = DataTypes.INTERVAL(DataTypes.HOUR())
interval_hour_to_minute = DataTypes.INTERVAL(DataTypes.HOUR(), DataTypes.MINUTE())
interval_hour_to_second = DataTypes.INTERVAL(DataTypes.HOUR(), DataTypes.SECOND(p2))

# Minute-based intervals
interval_minute = DataTypes.INTERVAL(DataTypes.MINUTE())
interval_minute_to_second = DataTypes.INTERVAL(DataTypes.MINUTE(), DataTypes.SECOND(p2))

# Second-based intervals
interval_second = DataTypes.INTERVAL(DataTypes.SECOND())
interval_second_with_param = DataTypes.INTERVAL(DataTypes.SECOND(p2))

Formats

The following table shows examples of the INTERVAL DAY TO SECOND type in different formats.

JSON for data type

{"type":"INTERVAL_DAY_TIME","nullable":true,"precision":1,"fractionalPrecision":3,"resolution":"DAY_TO_SECOND"}

CLI/UI format

INTERVAL DAY(1) TO SECOND(3)

JSON for payload

"+2 07:33:20.000"

CLI/UI format for payload

+2 07:33:20.000

INTERVAL YEAR TO MONTH

Data type for a group of year-month interval types.

Syntax

INTERVAL YEAR
INTERVAL YEAR(p)
INTERVAL YEAR(p) TO MONTH
INTERVAL MONTH

Example

CREATE TABLE test_sql_interval_y_to_m (val INTERVAL YEAR(2) TO MONTH);
INSERT INTO test_sql_interval_y_to_m VALUES (INTERVAL '2000-02' YEAR TO MONTH);

-- returns +2000-02
SELECT * FROM test_sql_interval_y_to_m;

Declare this type by using the above combinations, where p is the number of digits of years (year precision).

p must have a value between 1 and 4 (both inclusive). If no year precision is specified, p is equal to 2.

The type must be parameterized to one of these resolutions:

  • Interval of years

  • Interval of years to months

  • Interval of months

An interval of year-month consists of +years-months with values ranging from -9999-11 to +9999-11.

The value representation is the same for all types of resolutions. For example, an interval of months of 50 is always represented in an interval-of-years-to-months format (with default year precision): +04-02.

Formatting intervals are tricky, because they have different resolutions:

  • YEAR

  • YEAR_TO_MONTH

  • MONTH

Depending on the resolution, use:

INTERVAL YEAR(4)
INTERVAL YEAR(4) TO MONTH
INTERVAL MONTH

Syntax

Period

DataTypes.INTERVAL
import static org.apache.flink.table.api.DataTypes.*;

DataType intervalYear = INTERVAL(YEAR());
DataType intervalYearWithParam = INTERVAL(YEAR(p));
DataType intervalYearToMonth = INTERVAL(YEAR(p), MONTH());
DataType intervalMonth = INTERVAL(MONTH());

Bridging to JVM types

Java Type

Input

Output

Notes

java.time.Period

Default. Ignores the days part.

java.lang.Integer

Describes the number of months.

int

(✓)

Describes the number of months. Output only if type is not nullable.

Syntax

from pyflink.table.types import DataTypes

interval_year_to_month = DataTypes.INTERVAL(DataTypes.YEAR(p), DataTypes.MONTH())

Examples

from pyflink.table.types import DataTypes

interval_year = DataTypes.INTERVAL(DataTypes.YEAR())
interval_year_with_param = DataTypes.INTERVAL(DataTypes.YEAR(p))
interval_year_to_month = DataTypes.INTERVAL(DataTypes.YEAR(p), DataTypes.MONTH())
interval_month = DataTypes.INTERVAL(DataTypes.MONTH())

Formats

The following table shows examples of the INTERVAL YEAR TO MONTH type in different formats.

JSON for data type

{"type":"INTERVAL_YEAR_MONTH","nullable":true,"precision":4,"resolution":"YEAR_TO_MONTH"}

CLI/UI format

INTERVAL YEAR(4) TO MONTH

JSON for payload

"+2000-02"

CLI/UI format for payload

+2000-02

TIME

Represents a time without timezone consisting of hour:minute:second[.fractional] with up to nanosecond precision and values ranging from 00:00:00.000000000 to 23:59:59.999999999.

Syntax

TIME
TIME(p)

TIME_WITHOUT_TIME_ZONE
TIME_WITHOUT_TIME_ZONE(p)

Example

CREATE TABLE test_sql_time (val TIME(3));
INSERT INTO test_sql_time VALUES (CAST('10:56:22.541' AS TIME(3)));

-- returns 10:56:22.541
SELECT * FROM test_sql_time;

Declare this type by using TIME(p), where p is the number of digits of fractional seconds (precision).

p must have a value between 0 and 9 (both inclusive). If no precision is specified, p is equal to 0.

Compared to the SQL standard, leap seconds (23:59:60 and 23:59:61) are not supported, as the semantics are closer to java.time.LocalTime.

A time with timezone is not provided.

TIME acts like a pure string and isn’t related to a time zone of any kind, including UTC.

TIME WITHOUT TIME ZONE is a synonym for this type.

Syntax

Time
TimeWithoutTimeZone

DataTypes.TIME()
DataTypes.TIME(p)

DataTypes.TIME_WITHOUT_TIME_ZONE()
DataTypes.TIME_WITHOUT_TIME_ZONE(p)

Examples

import static org.apache.flink.table.api.DataTypes.*;

DataType time = TIME();
DataType timeWithPrecision = TIME(p);

DataType timeWithoutTimeZone = TIME_WITHOUT_TIME_ZONE();
DataType timeWithoutTimeZoneWithPrecision = TIME_WITHOUT_TIME_ZONE(p);

Bridging to JVM types

Java Type

Input

Output

Notes

java.time.LocalTime

Default

java.sql.Time

java.lang.Integer

Describes the number of milliseconds of the day.

int

(✓)

Describes the number of milliseconds of the day. Output only if type is not nullable.

java.lang.Long

Describes the number of nanoseconds of the day.

long

(✓)

Describes the number of nanoseconds of the day. Output only if type is not nullable.

Syntax

from pyflink.table.types import DataTypes

DataTypes.TIME()
DataTypes.TIME(p)

DataTypes.TIME_WITHOUT_TIME_ZONE()
DataTypes.TIME_WITHOUT_TIME_ZONE(p)

Examples

from pyflink.table.types import DataTypes

time_type = DataTypes.TIME()
time_with_param = DataTypes.TIME(p)

time_without_tz = DataTypes.TIME_WITHOUT_TIME_ZONE()
time_without_tz_with_param = DataTypes.TIME_WITHOUT_TIME_ZONE(p)

The precision specified in p must be 0.

Formats

The following table shows examples of the TIME type in different formats.

JSON for data type

{"type":"TIME_WITHOUT_TIME_ZONE","nullable":true,"precision":3}

CLI/UI format

TIME(3)

JSON for payload

"10:56:22.541"

CLI/UI format for payload

10:56:22.541

TIMESTAMP

Represents a timestamp without timezone consisting of year-month-day hour:minute:second[.fractional] with up to nanosecond precision and values ranging from 0000-01-01 00:00:00.000000000 to 9999-12-31 23:59:59.999999999.

Syntax

TIMESTAMP
TIMESTAMP(p)

TIMESTAMP WITHOUT TIME ZONE
TIMESTAMP(p) WITHOUT TIME ZONE

Example

CREATE TABLE test_sql_timestamp (val TIMESTAMP(3));
INSERT INTO test_sql_timestamp VALUES (CAST('2023-04-06 10:59:32.628' AS TIMESTAMP(3)));

-- returns 2023-04-06 10:59:32.628
SELECT * FROM test_sql_timestamp;

Declare this type by using TIMESTAMP(p), where p is the number of digits of fractional seconds (precision).

p must have a value between 0 and 9 (both inclusive). If no precision is specified, p is equal to 6.

A space separates the date and time parts.

Compared to the SQL standard, leap seconds (23:59:60 and 23:59:61) are not supported, as the semantics are closer to java.time.LocalDateTime.

A conversion from and to BIGINT (a JVM long type) is not supported, as this would imply a timezone, but this type is time-zone free. For more java.time.Instant-like semantics use TIMESTAMP_LTZ.

TIMESTAMP acts like a pure string and isn’t related to a time zone of any kind, including UTC.

TIMESTAMP WITHOUT TIME ZONE is a synonym for this type.

Syntax

Timestamp

DataTypes.TIMESTAMP(p)

Examples

import static org.apache.flink.table.api.DataTypes.*;

DataType timestamp = TIMESTAMP();
DataType timestampWithPrecision = TIMESTAMP(p);

Bridging to JVM types

Java Type

Input

Output

Notes

java.time.LocalDateTime

Default

java.sql.Timestamp

org.apache.flink.table.data.TimestampData

Internal data structure

Syntax

from pyflink.table.types import DataTypes

DataTypes.TIMESTAMP(p)

Examples

from pyflink.table.types import DataTypes

timestamp = DataTypes.TIMESTAMP()
timestamp_with_precision = DataTypes.TIMESTAMP(p)

The precision specified in p must be 3.

Formats

The following table shows examples of the TIMESTAMP type in different formats.

JSON for data type

{"type":"TIMESTAMP_WITHOUT_TIME_ZONE","nullable":true,"precision":3}

CLI/UI format

TIMESTAMP(3)

JSON for payload

"2023-04-06 10:59:32.628"

CLI/UI format for payload

2023-04-06 10:59:32.628

TIMESTAMP_LTZ

Represents a timestamp with the local timezone consisting of year-month-day hour:minute:second[.fractional] zone with up to nanosecond precision and values ranging from 0000-01-01 00:00:00.000000000 +14:59 to 9999-12-31 23:59:59.999999999 -14:59.

Syntax

TIMESTAMP_LTZ
TIMESTAMP_LTZ(p)

TIMESTAMP WITH LOCAL TIME ZONE
TIMESTAMP(p) WITH LOCAL TIME ZONE

Example

CREATE TABLE test_sql_timestamp_ltz (val TIMESTAMP_LTZ(3));
INSERT INTO test_sql_timestamp_ltz VALUES (CAST('2023-04-06 10:59:32.628' AS TIMESTAMP_LTZ(3)));

-- returns 2023-04-06 10:59:32.628
SELECT * FROM test_sql_timestamp_ltz;

Declare this type by using TIMESTAMP_LTZ(p), where p is the number of digits of fractional seconds (precision).

p must have a value between 0 and 9 (both inclusive). If no precision is specified, p is equal to 6.

Leap seconds (23:59:60 and 23:59:61) are not supported, as the semantics are closer to java.time.OffsetDateTime.

Compared to TIMESTAMP WITH TIME ZONE, the timezone offset information is not stored physically in every datum. Instead, the type assumes java.time.Instant semantics in the UTC timezone at the edges of the table ecosystem. Every datum is interpreted in the local timezone configured in the current session for computation and visualization.

This type fills the gap between time-zone free and time-zone mandatory timestamp types by allowing the interpretation of UTC timestamps according to the configured session timezone.

TIMESTAMP_LTZ resembles a TIMESTAMP without a timezone, but the string always considers the sessions/query’s timezone. Internally, it is always in the UTC time zone.

If you require the short format, prefer TIMESTAMP_LTZ(3).

TIMESTAMP WITH LOCAL TIME ZONE is a synonym for this type.

Syntax

DataTypes.TIMESTAMP_LTZ(p)

DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(p)

Examples

import static org.apache.flink.table.api.DataTypes.*;

DataType timestamp_ltz = TIMESTAMP_LTZ(p);
DataType timestamp_with_local_time_zone = TIMESTAMP_WITH_LOCAL_TIME_ZONE(p);

Bridging to JVM types

Java Type

Input

Output

Notes

java.time.Instant

Default

java.lang.Integer

Describes the number of seconds since Unix epoch.

int

(✓)

Describes the number of seconds since Unix epoch. Output only if type is not nullable.

java.lang.Long

Describes the number of milliseconds since Unix epoch.

long

(✓)

Describes the number of milliseconds since Unix epoch. Output only if type is not nullable.

java.sql.Timestamp

Describes the number of milliseconds since Unix epoch.

org.apache.flink.table.data.TimestampData

Internal data structure

Syntax

from pyflink.table.types import DataTypes

DataTypes.TIMESTAMP_LTZ(p)
DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(p)

Examples

from pyflink.table.types import DataTypes

timestamp_ltz = DataTypes.TIMESTAMP_LTZ(p)
timestamp_with_local_time_zone = DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(p)

The precision specified in p must be 3.

Formats

The following table shows examples of the TIMESTAMP_LTZ type in different formats.

JSON for data type

{"type":"TIMESTAMP_WITH_LOCAL_TIME_ZONE","nullable":true,"precision":3}

CLI/UI format

TIMESTAMP(3) WITH LOCAL TIME ZONE

JSON for payload

"2023-04-06 11:06:47.224"

CLI/UI format for payload

2023-04-06 11:06:47.224

TIMESTAMP and TIMESTAMP_LTZ comparison

Although TIMESTAMP and TIMESTAMP_LTZ are similarly named, they represent different concepts.

TIMESTAMP_LTZ
  • TIMESTAMP_LTZ in SQL is similar to the Instant class in Java.

  • TIMESTAMP_LTZ represents a moment, or a specific point in the UTC timeline.

  • TIMESTAMP_LTZ stores time as a UTC integer, which can be converted dynamically to every other timezone.

  • When printing or casting TIMESTAMP_LTZ as a character string, the sql.local-time-zone setting is considered.

TIMESTAMP
  • TIMESTAMP in SQL is similar to LocalDateTime in Java.

  • TIMESTAMP has no time zone or offset from UTC, so it can’t represent a moment.

  • TIMESTAMP stores time as character string, not related to any timezone.

TIMESTAMP WITH TIME ZONE

Represents a timestamp with time zone consisting of year-month-day hour:minute:second[.fractional] zone with up to nanosecond precision and values ranging from 0000-01-01 00:00:00.000000000 +14:59 to 9999-12-31 23:59:59.999999999 -14:59.

Syntax

TIMESTAMP WITH TIME ZONE
TIMESTAMP(p) WITH TIME ZONE

Example

CREATE TABLE test_sql_timestamp_with_time_zone (val TIMESTAMP(3) WITH TIME ZONE);
INSERT INTO test_sql_timestamp_with_time_zone VALUES (CAST('2023-04-06 10:59:32.628 +08:00' AS TIMESTAMP(3) WITH TIME ZONE));

-- returns 2023-04-06 10:59:32.628 +08:00
SELECT * FROM test_sql_timestamp_with_time_zone;

Compared to TIMESTAMP_LTZ, the time zone offset information is stored physically in every datum. It is used individually for every computation, visualization, or communication to external systems.

Syntax

OffsetDateTime
DataTypes.TIMESTAMP_WITH_TIME_ZONE()
DataTypes.TIMESTAMP_WITH_TIME_ZONE(p)

Examples

import static org.apache.flink.table.api.DataTypes.*;

OffsetDateTime offsetDateTime = OffsetDateTime.of(2023, 4, 6, 10, 59, 32, 628, ZoneOffset.of("+08:00"));

DataType timestamp_with_time_zone = TIMESTAMP_WITH_TIME_ZONE();
DataType timestamp_with_time_zone_with_precision = TIMESTAMP_WITH_TIME_ZONE(p);

Bridging to JVM types

Java Type

Input

Output

Notes

java.time.OffsetDateTime

Default

java.time.ZonedDateTime

Ignores the zone ID

Syntax

from pyflink.table.types import DataTypes

DataTypes.TIMESTAMP_WITH_TIME_ZONE(p)

Examples

from pyflink.table.types import DataTypes

timestamp_with_time_zone = DataTypes.TIMESTAMP_WITH_TIME_ZONE(p)

Not supported.

Collection data types

ARRAY

Represents an array of elements with same subtype.

Syntax

ARRAY<t>
t ARRAY

Example

CREATE TABLE test_sql_array (val ARRAY<INT>);
INSERT INTO test_sql_array VALUES (ARRAY[1, 2, 3]);

-- returns [1, 2, 3]
SELECT * FROM test_sql_array;

Declare this type by using ARRAY<t>, where t is the data type of the contained elements.

Compared to the SQL standard, the maximum cardinality of an array cannot be specified and is fixed at 2,147,483,647. Also, any valid type is supported as a subtype.

t ARRAY is a synonym for being closer to the SQL standard. For example, INT ARRAY is equivalent to ARRAY<INT>.

Syntax

t[]

DataTypes.ARRAY(t)

Examples

int[] intArray = new int[] {1, 2, 3};

import static org.apache.flink.table.api.DataTypes.*;

DataType array = ARRAY(t);
DataType arrayWithPrecision = ARRAY(p);

Bridging to JVM types

Java Type

Input

Output

Notes

t[]

(✓)

(✓)

Default. Depends on the subtype.

java.util.List<t>

subclass of java.util.List<t>

org.apache.flink.table.data.ArrayData

Internal data structure

Syntax

from pyflink.table.types import DataTypes

DataTypes.ARRAY(t)

Examples

from pyflink.table.types import DataTypes

array = DataTypes.ARRAY(t)
array_with_precision = DataTypes.ARRAY(p)

Formats

The following table shows examples of the ARRAY type in different formats.

JSON for data type

{"type":"ARRAY","nullable":true,"elementType":{"type":"INTEGER","nullable":true}}

CLI/UI format

ARRAY<INT>

JSON for payload

["1", "2", "3", null]

CLI/UI format for payload

[1, 2, 3, NULL]

MAP

Represents an associative array that maps keys (including NULL) to values (including NULL).

Syntax

MAP<kt, vt>

Example

CREATE TABLE test_sql_map (val MAP<STRING, INT>);
INSERT INTO test_sql_map VALUES (MAP['a', 1, 'b', 2, 'c', 3]);

-- returns {a=1, b=2, c=3}
SELECT * FROM test_sql_map;

Declare this type by using MAP<kt, vt> where kt is the data type of the key elements and vt is the data type of the value elements.

A map can’t contain duplicate keys. Each key can map to at most one value.

There is no restriction of element types. It is the responsibility of the user to ensure uniqueness.

The map type is an extension to the SQL standard.

Syntax

Map<kt, vt>

DataTypes.MAP(kt, vt)

Examples

Map<String, Integer> stringIntegerMap = new HashMap<>();

import static org.apache.flink.table.api.DataTypes.*;

DataType map = MAP(kt, vt);

Bridging to JVM types

Java Type

Input

Output

Notes

java.util.Map<kt, vt>

Default

subclass of java.util.Map<kt, vt>

org.apache.flink.table.data.MapData

Internal data structure

Syntax

DataTypes.MAP(kt, vt)

Examples

from pyflink.table.types import DataTypes

map = DataTypes.MAP(kt, vt)

Formats

The following table shows examples of the MAP type in different formats.

JSON for data type

{"type":"MAP","nullable":true,"keyType":{"type":"INTEGER","nullable":true},"valueType":{"type":"VARCHAR","nullable":true,"length":2147483647}}

CLI/UI format

MAP<STRING>

JSON for payload

[["1", "a"], ["2", "b"], [null, "c"]]

CLI/UI format for payload

{1=a, 2=b, NULL=c}

MULTISET

Represents a multiset (=bag).

Syntax

MULTISET<t>
t MULTISET

Example

CREATE TABLE test_sql_multiset (val MULTISET<INT>);
INSERT INTO test_sql_multiset
  SELECT COLLECT(val) FROM (VALUES 1, 2, 3, 2) AS t(val);

-- returns {1, 2, 3, 2}
SELECT * FROM test_sql_multiset;

Declare this type by using MULTISET<t> where t is the data type of the contained elements.

Unlike a set, the multiset allows for multiple instances for each of its elements with a common subtype. Each unique value (including NULL) is mapped to some multiplicity.

There is no restriction of element types; it is the responsibility of the user to ensure uniqueness.

t MULTISET is a synonym for being closer to the SQL standard. For example, INT MULTISET is equivalent to MULTISET<INT>.

Syntax

DataTypes.MULTISET(t)

Examples

import static org.apache.flink.table.api.DataTypes.*;

DataType multiset = MULTISET(t);

Bridging to JVM types

Java Type

Input

Output

Notes

java.util.Map<t, java.lang.Integer>

Default. Assigns each value to an integer multiplicity.

subclass of java.util.Map<t, java.lang.Integer>

org.apache.flink.table.data.MapData

Internal data structure

Syntax

DataTypes.MULTISET(t)

Examples

from pyflink.table.types import DataTypes

multiset = DataTypes.MULTISET(t)

Formats

The following table shows examples of the MULTISET type in different formats.

JSON for data type

{"type":"MULTISET","nullable":true,"elementType":{"type":"INTEGER","nullable":true}}

CLI/UI format

MULTISET<INT>

JSON for payload

[["a", "1"], ["b", "2"], [null, "1"]]

CLI/UI format for payload

{a=1, b=2, NULL=1}

ROW

Represents a sequence of fields.

Syntax

ROW<name0 type0, name1 type1, ...>
ROW<name0 type0 'description0', name1 type1 'description1', ...>

ROW(name0 type0, name1 type1, ...)
ROW(name0 type0 'description0', name1 type1 'description1', ...)

Example

CREATE TABLE test_sql_row (val ROW<name STRING, age INT>);
INSERT INTO test_sql_row VALUES (('Alice', 30)), (('Bob',45));

-- returns ('Alice', 30), ('Bob', 45)
SELECT * FROM test_sql_row;

Declare this type by using ROW<n0 t0 'd0', n1 t1 'd1', ...>, where n is the unique name of a field, t is the logical type of a field, d is the description of a field.

A field consists of a field name, field type, and an optional description. The most specific type of a row of a table is a row type. In this case, each column of the row corresponds to the field of the row type that has the same ordinal position as the column.

To create a table with a row type, use the following syntax:

CREATE TABLE table_with_row_types (
   `Customer` ROW<name STRING, age INT>,
   `Order` ROW<id BIGINT, title STRING>
);

To insert a row into a table with a row type, use the following syntax:

INSERT INTO table_with_row_types VALUES
   (('Alice', 30), (101, 'Book')),
   (('Bob', 25), (102, 'Laptop')),
   (('Charlie', 35), (103, 'Phone')),
   (('Diana', 28), (104, 'Tablet')),
   (('Eve', 22), (105, 'Headphones'));

To work with fields from a row, use dot notation:

SELECT `Customer`.name, `Customer`.age, `Order`.id, `Order`.title
FROM table_with_row_types
WHERE `Customer`.age > 30;

Compared to the SQL standard, an optional field description simplifies the handling with complex structures.

A row type is similar to the STRUCT type known from other non-standard-compliant frameworks.

ROW(...) is a synonym for being closer to the SQL standard. For example, ROW(fieldOne INT, fieldTwo BOOLEAN) is equivalent to ROW<fieldOne INT, fieldTwo BOOLEAN>.

If the fields of the data type contain characters other than [A-Za-z_], use escaping notation. Double backticks escape the backtick character, for example:

ROW<`a-b` INT, b STRING, `weird_col``_umn` STRING>

Rows fields can contain comments, for example:

{"type":"ROW","nullable":true,"fields":[{"name":"a","fieldType":{"type":"INTEGER","nullable":true},"description":"hello"}]}

Format using single quotes. Double single quotes escape single quotes, for example:

ROW<a INT 'This field''s content'>

Syntax

DataTypes.ROW(DataTypes.FIELD(n0, t0), DataTypes.FIELD(n1, t1), ...)
DataTypes.ROW(DataTypes.FIELD(n0, t0, d0), DataTypes.FIELD(n1, t1, d1), ...)

Examples

import static org.apache.flink.table.api.DataTypes.*;

DataType row = ROW(DataTypes.FIELD("name", DataTypes.STRING()), DataTypes.FIELD("age", DataTypes.INT()));
DataType rowWithDescription = ROW(DataTypes.FIELD("name", DataTypes.STRING(), "name"), DataTypes.FIELD("age", DataTypes.INT(), "age"));

Bridging to JVM types

Java Type

Input

Output

Notes

org.apache.flink.types.Row

Default

org.apache.flink.table.data.RowData

Internal data structure

Syntax

from pyflink.table import DataTypes

DataTypes.ROW([DataTypes.FIELD(..), DataTypes.FIELD(..), ...])

Examples

from pyflink.table import DataTypes

row = DataTypes.ROW([
   DataTypes.FIELD("id", DataTypes.INT()),
   DataTypes.FIELD("data", DataTypes.STRING())
])

Formats

The following table shows examples of the ROW type in different formats.

JSON for data type

{"type":"ROW","nullable":true,"fields":[{"name":"a","fieldType":{"type":"INTEGER","nullable":true}},{"name":"b","fieldType":{"type":"VARCHAR","nullable":true,"length":2147483647}}]}

CLI/UI format

MULTISET<INT>

JSON for payload

[["a", "1"], ["b", "2"], [null, "1"]]

CLI/UI format for payload

{a=1, b=2, NULL=1}

Other data types

BOOLEAN

Represents a boolean with a (possibly) three-valued logic of TRUE, FALSE, and UNKNOWN.

Syntax

BOOLEAN

Example

CREATE TABLE test_sql_boolean (val BOOLEAN);
INSERT INTO test_sql_boolean VALUES (TRUE), (FALSE), (UNKNOWN);

-- returns TRUE, FALSE, NULL
SELECT * FROM test_sql_boolean;

Syntax

boolean

DataTypes.BOOLEAN()

Examples

boolean booleanValue = true;

import static org.apache.flink.table.api.DataTypes.*;

DataType boolean = BOOLEAN();

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.Boolean

Default

boolean

(✓)

Output only if type is not nullable.

Syntax

DataTypes.BOOLEAN()

Examples

from pyflink.table import DataTypes

boolean = DataTypes.BOOLEAN()
boolean_value = True

Formats

The following table shows examples of the BOOLEAN type in different formats.

JSON for data type

{"type":"BOOLEAN","nullable":true}

CLI/UI format

NULL

JSON for payload

null

CLI/UI format for payload

NULL

NULL

Data type for representing untyped NULL values.

Syntax

NULL

The NULL type is an extension to the SQL standard. A NULL type has no other value except NULL, thus, it can be cast to any nullable type similar to JVM semantics.

This type helps in representing unknown types in API calls that use a NULL literal as well as bridging to formats such as JSON or Avro that define such a type as well.

This type is not very useful in practice and is described here only for completeness.

Syntax

DataTypes.NULL()

Examples

import static org.apache.flink.table.api.DataTypes.*;

DataType null = NULL();

Bridging to JVM types

Java Type

Input

Output

Notes

java.lang.Object

Default

any class

(✓)

Any non-primitive type.

Syntax

DataTypes.NULL()

Examples

from pyflink.table import DataTypes

null = DataTypes.NULL()

Formats

The following table shows examples of the NULL type in different formats.

JSON for data type

{"type":"NULL"}

CLI/UI format

NULL

JSON for payload

null

CLI/UI format for payload

NULL

Casting

Flink SQL can perform casting between a defined input type and target type. While some casting operations can always succeed regardless of the input value, others can fail at runtime when there’s no way to create a value for the target type. For example, it’s always possible to convert INT to STRING, but you can’t always convert a STRING to INT.

During the planning stage, the query validator rejects queries for invalid type pairs with a ValidationException, for example, when trying to cast a TIMESTAMP to an INTERVAL. Valid type pairs that can fail at runtime are accepted by the query validator, but this requires you to handle cast failures correctly.

In Flink SQL, casting can be performed by using one of these two built-in functions:

  • CAST: The regular cast function defined by the SQL standard. It can fail the job if the cast operation is fallible and the provided input is not valid. Type inference preserves the nullability of the input type.

  • TRY_CAST: An extension to the regular cast function that returns NULL if the cast operation fails. Its return type is always nullable.

For example:

-- returns 42 of type INT NOT NULL
SELECT CAST('42' AS INT);

-- returns NULL of type VARCHAR
SELECT CAST(NULL AS VARCHAR);

-- throws an exception and fails the job
SELECT CAST('non-number' AS INT);

-- returns 42 of type INT
SELECT TRY_CAST('42' AS INT);

-- returns NULL of type VARCHAR
SELECT TRY_CAST(NULL AS VARCHAR);

-- returns NULL of type INT
SELECT TRY_CAST('non-number' AS INT);

-- returns 0 of type INT NOT NULL
SELECT COALESCE(TRY_CAST('non-number' AS INT), 0);

The following matrix shows the supported cast pairs, where “Y” means supported, “!” means fallible, and “N” means unsupported:

Input / Target

CHAR¹ / VARCHAR¹ / STRING

BINARY¹ / VARBINARY¹ / BYTES

BOOLEAN

DECIMAL

TINYINT

SMALLINT

INTEGER

BIGINT

FLOAT

DOUBLE

DATE

TIME

TIMESTAMP

TIMESTAMP_LTZ

INTERVAL

ARRAY

MULTISET

MAP

ROW

CHAR / VARCHAR / STRING

Y

!

!

!

!

!

!

!

!

!

!

!

!

!

N

N

N

N

N

BINARY / VARBINARY / BYTES

Y

Y

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

BOOLEAN

Y

N

Y

Y

Y

Y

Y

Y

Y

Y

N

N

N

N

N

N

N

N

N

DECIMAL

Y

N

N

Y

Y

Y

Y

Y

Y

Y

N

N

N

N

N

N

N

N

N

TINYINT

Y

N

Y

Y

Y

Y

Y

Y

Y

Y

N

N

N

N

N

N

N

SMALLINT

Y

N

Y

Y

Y

Y

Y

Y

Y

Y

N

N

N

N

N

N

N

INTEGER

Y

N

Y

Y

Y

Y

Y

Y

Y

Y

N

N

Y⁵

N

N

N

N

BIGINT

Y

N

Y

Y

Y

Y

Y

Y

Y

Y

N

N

Y⁶

N

N

N

N

FLOAT

Y

N

N

Y

Y

Y

Y

Y

Y

Y

N

N

N

N

N

N

N

N

N

DOUBLE

Y

N

N

Y

Y

Y

Y

Y

Y

Y

N

N

N

N

N

N

N

N

N

DATE

Y

N

N

N

N

N

N

N

N

N

Y

N

Y

Y

N

N

N

N

N

TIME

Y

N

N

N

N

N

N

N

N

N

N

Y

Y

Y

N

N

N

N

N

TIMESTAMP

Y

N

N

N

N

N

N

N

N

N

Y

Y

Y

Y

N

N

N

N

N

TIMESTAMP_LTZ

Y

N

N

N

N

N

N

N

N

N

Y

Y

Y

Y

N

N

N

N

N

INTERVAL

Y

N

N

N

N

N

Y⁵

Y⁶

N

N

N

N

N

N

Y

N

N

N

N

ARRAY

Y

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

MULTISET

Y

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

MAP

Y

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

ROW

Y

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

Notes:

  1. All the casting to constant length or variable length also trims and pads, according to the type definition.

  2. TO_TIMESTAMP and TO_TIMESTAMP_LTZ must be used instead of CAST/ TRY_CAST.

  3. Supported iff the children type pairs are supported. Fallible iff the children type pairs are fallible.

  4. Supported iff the RAW class and serializer are equals.

  5. Supported iff INTERVAL is a MONTH TO YEAR range.

  6. Supported iff INTERVAL is a DAY TO TIME range.

Note

A cast of a NULL value always returns NULL, regardless of whether the function used is CAST or TRY_CAST.

Data type extraction

In many locations in the API, Flink tries to extract data types automatically from class information by using reflection to avoid repetitive manual schema work. But extracting a data type using reflection is not always successful, because logical information might be missing. In these cases, it may be necessary to add additional information close to a class or field declaration for supporting the extraction logic.

The following table lists classes that map implicitly to a data type without requiring further information. Other JVM bridging classes require the @DataTypeHint annotation.

Class

Data Type

boolean

BOOLEAN NOT NULL

byte

TINYINT NOT NULL

byte[]

BYTES

double

DOUBLE NOT NULL

float

FLOAT NOT NULL

int

INT NOT NULL

java.lang.Boolean

BOOLEAN

java.lang.Byte

TINYINT

java.lang.Double

DOUBLE

java.lang.Float

FLOAT

java.lang.Integer

INT

java.lang.Long

BIGINT

java.lang.Short

SMALLINT

java.lang.String

STRING

java.sql.Date

DATE

java.sql.Time

TIME(0)

java.sql.Timestamp

TIMESTAMP(9)

java.time.Duration

INTERVAL SECOND(9)

java.time.Instant

TIMESTAMP_LTZ(9)

java.time.LocalDate

DATE

java.time.LocalTime

TIME(9)

java.time.LocalDateTime

TIMESTAMP(9)

java.time.OffsetDateTime

TIMESTAMP(9) WITH TIME ZONE

java.time.Period

INTERVAL YEAR(4) TO MONTH

java.util.Map<K, V>

MAP<K, V>

short

SMALLINT NOT NULL

structured type T

anonymous structured type T

long

BIGINT NOT NULL

T[]

ARRAY<T>