Skip to main content
Important The VARIANT type is supported only for tables in Iceberg Catalog and Paimon Catalog. It is not supported by native tables. From v4.1 onwards, the database supports the VARIANT data type for querying semi-structured data from Iceberg tables in Parquet format. From v4.2 onwards, the database also supports the VARIANT data type for querying semi-structured data from Paimon tables. This article introduces the basic concepts of VARIANT, and how the database queries VARIANT-type data and processes it through VARIANT functions.

What is VARIANT

VARIANT is a semi-structured data type that can store values of different data types, including primitive types (integers, floating-point numbers, strings, booleans, dates, timestamps), and complex types (structs, maps, arrays). VARIANT data is encoded in binary format for efficient storage and querying. The VARIANT type is particularly useful when working with data from Apache Iceberg tables that use the Parquet format with variant encoding, which allows for flexible schema evolution and efficient storage of heterogeneous data. For more information on the Parquet variant encoding format, see the Parquet Variant Encoding specification.

Using VARIANT Data

Querying VARIANT-Type Data from Iceberg Tables

The database supports querying VARIANT-type data from Iceberg tables stored in Parquet format. VARIANT columns are automatically recognized when querying Iceberg tables that use Parquet’s variant encoding. Example of querying an Iceberg table with VARIANT columns:

Extracting Values from VARIANT Data

The database provides several functions to extract typed values from VARIANT data. Example 1: Extract primitive values using typed getter functions.
Example 2: Navigate nested structures using JSON path expressions.
Example 3: Access array elements.
Example 4: Query nested variant data and return VARIANT type.
Example 5: Check the type of a VARIANT value.

Casting JSON to VARIANT

The database supports casting JSON values to VARIANT. If your input is a STRING, convert it to JSON first.

Casting VARIANT Data to SQL Types

You can use the CAST function to convert VARIANT data to standard SQL types:
Complex types can also be cast from VARIANT:

Casting SQL Types to VARIANT

You can cast SQL values to VARIANT. Supported input types include BOOLEAN, integer types, FLOAT/DOUBLE, DECIMAL, STRING/CHAR/VARCHAR, JSON, DATE/DATETIME/TIME, and complex types (ARRAY, MAP, STRUCT). For MAP, keys are cast to strings during encoding. Types such as HLL, BITMAP, PERCENTILE, and VARBINARY are not supported.

VARIANT Functions

VARIANT functions can be used to query and extract data from VARIANT columns. For detailed information, please refer to the individual function documentation:
  • variant_query: Queries a path in a VARIANT value and returns a VARIANT
  • get_variant: Extracts typed values (int, bool, double, string) from a VARIANT
  • variant_typeof: Returns the type name of a VARIANT value

VARIANT Path Expressions

VARIANT functions use JSON path expressions to navigate through the data structure. The path syntax is similar to JSON path:
  • $ represents the root of the VARIANT value
  • . is used to access object fields
  • [index] is used to access array elements (0-based indexing)
  • Field names with special characters (like dots) can be quoted: $."field.name"
Examples of path expressions:

Data Type Conversion

When data is read from Parquet files with variant encoding, the following type conversions are supported:

Limitations and Considerations

  • VARIANT is supported for reading data from Iceberg tables in Parquet format with variant encoding, and for writing Parquet files using the database file writers (unshredded variant encoding).
  • VARIANT is also supported for reading data from Paimon tables (Paimon requires Parquet for variant columns), but only for splits read by the native reader (append-only tables and compacted primary-key data). Reading VARIANT from uncompacted primary-key data requires the JNI reader and is not yet supported; such queries are rejected with a plan-time error.
  • The size of a VARIANT value is limited to 16 MB.
  • Currently only unshredded variant values are supported for both read and write.
  • VARIANT can be created by casting from JSON values or supported SQL types (including ARRAY, MAP, and STRUCT).
  • The maximum depth of nested structures depends on the underlying Parquet file structure.