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:
|
| 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
- 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'); - 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; - 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') */;
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot