Help Center/ AI DataLake/ Flink reference/ Enhanced Flink Features/ Flink on Iceberg Supporting the VARIANT Data Type
Updated on 2026-11-06 GMT+08:00

Flink on Iceberg Supporting the VARIANT Data Type

Scenario

Flink writes data to Iceberg and supports dynamic and nested semi-structured data.

Notes and Constraints

  • Only Iceberg V3 tables are supported.
  • Only the Iceberg Parquet format is supported.

Related Functions

VARIANT PARSE_JSON(VARCHAR jsonStr [, BOOLEAN allowDuplicateKeys])
VARIANT TRY_PARSE_JSON(VARCHAR jsonStr [, BOOLEAN allowDuplicateKeys])

Parameter

Data Type

Description

jsonStr

VARCHAR

JSON string to be parsed.

If the value of the jsonStr parameter is NULL, the return value is NULL.

allowDuplicateKeys

BOOLEAN

Optional. The options are as follows:

  • true: Retains the value of the last duplicate key in the JSON string.
  • false (default): Returns NULL if duplicate keys exist in the JSON string.

Function

Default Error Handling

Return Value for Invalid JSON

Fault Tolerance

PARSE_JSON

An explicit error is reported.

An exception is thrown by default.

The validity of the input must be strictly verified.

TRY_PARSE_JSON

Fails silently.

NULL is returned by default.

Abnormal data streams must be compatible.

Usage

  1. Create a new Iceberg table, for example, iceberg_catalog.`default`.iceberg_table. The following is a code example:

    CREATE TABLE IF NOT EXISTS iceberg_catalog.`default`.iceberg_table (
      id BIGINT,
      test_data1 VARIANT, 
      test_data2 VARIANT
    ) WITH
      ('format-version' = '3');

  2. Write data of the VARIANT type. SQL example:

    CREATE TABLE datagen (id BIGINT)
    WITH
      (
        'connector' = 'datagen',
        'rows-per-second' = '1'
      );
    
    INSERT INTO
      iceberg_catalog.`default`.iceberg_table
    SELECT
      id,
      PARSE_JSON (
        '{"user":{"name":"Bob","address":{"city":"Shanghai","zip":"200000"}},"tags":["dev","flink"]}'
      ),
      TRY_PARSE_JSON (
        '{"user":{"name":"Bob","address":{"city":"Shanghai","zip":"200000"}},"tags":["dev","flink"]}'
      )
    FROM
      datagen;

  3. Read data of the VARIANT type. SQL example:

    CREATE TABLE print
    WITH
      ('connector' = 'print') AS
    SELECT
      id,
      JSON_VALUE (test_data1, '$.user.name'),
      JSON_VALUE (test_data2, '$.tags[0]')
    FROM
      iceberg_catalog.`default`.iceberg_table /*+ OPTIONS('streaming'='true', 'monitor-interval'='60s') */;