Jump to content

Variant type

From Open Lakehouse Wiki
Variant type
Also known as VARIANT, variant data type
Field Data types, semi-structured data
Introduced Apache Spark 4.0.0 (2025); Parquet format 2.11.0; Iceberg format v3; Delta Lake 4.0.0
Key parts metadata and value binaries, primitive / array / object values, shredding into typed_value columns
Open source implementations Apache Spark, Apache Parquet, Apache Iceberg, Delta Lake
Related Logical type, Open table format, Predicate pushdown
Last verified 22 November 2026 against the v4.3.0 tag of apache/spark, the Spark 4.0.0, 4.1.0 and 4.3.0 release notes, apache/parquet-format tags 2.11.0 and 2.14.0, the Apache Iceberg table spec, Delta Lake PROTOCOL.md at v4.4.1 and the Delta and Iceberg release notes.

A variant (SQL type VARIANT) is a data type for semi-structured data such as JSON, in which each value carries its own structure in a compact binary encoding, so that rows in the same column can have different shapes and nested fields can be read by path without a fixed schema.[1] In the open lakehouse, the same variant binary encoding is defined once in the Apache Parquet project and referenced by Apache Spark, the Apache Iceberg table spec and the Delta Lake protocol.[2][3][4]

Encoding

The Variant Binary Encoding specification defines a variant as one of three things: a primitive (a type and a value, such as an integer or a string), an array (an ordered list of variant values) or an object (an unordered set of string keys with variant values, without duplicate keys). Each variant is stored as two binary values:[1]

  • metadata: a header and a dictionary of the field-name strings used in the value.
  • value: the encoded data. Object keys are stored as indexes into the metadata dictionary.

The specification states that the encoding is designed for efficient access by path, even in very wide or deep structures, and that each nested value is contiguous and self-contained: an inner value, paired with the metadata of the whole variant, is itself a valid variant.[1] The allowed primitive types are a subset of Parquet's logical types.[1]

In a Parquet file, a variant column is a group annotated with the VARIANT logical type that contains a required binary field metadata and a binary field value. The value field is required for an unshredded variant and optional when parts of the value are shredded.[5]

optional group event (VARIANT(1)) {
  required binary metadata;
  required binary value;
}

Shredding

Shredding stores selected paths of a variant as ordinary typed Parquet columns next to the binary value. Each value field may have a sibling field named typed_value that holds the value when it matches a given type, and readers must reconstruct the full variant from both. All field names stay in the shared metadata.[6]

The shredding specification gives the reason: data is often partly homogeneous, and shredded fields gain columnar encoding, column statistics for data skipping and partial projection. A query that extracts one field from a variant can read only that shredded column, and a filter on a shredded field can use its statistics to skip data.[6] Shredding is a storage choice. It does not change the logical value a reader returns.

Origin of the specification

The variant encoding began in Apache Spark. In 2024 the Spark and Parquet communities agreed to move the Spark variant specification into the Parquet project, tracked as parquet-format issue 455.[7] VariantEncoding.md, VariantShredding.md and the VARIANT logical type are present in parquet-format from release 2.11.0, and are not in 2.10.0.[5]

At the v4.3.0 tag, Spark's own variant README says the spec "is being developed in the Apache Parquet project", that Spark implements a specific commit of the Parquet spec, and that Spark does not yet support variant values containing UUID, Time or nanosecond-precision timestamps.[2]

Apache Spark

Spark 4.0.0 added the VARIANT data type (SPARK-45827), with VariantVal for PySpark, variant support in PySpark UDFs, UDTFs and UDAFs, and variant support in the Spark Connect Scala client.[8] Spark 4.1.0 describes VARIANT as generally available "with shredding for faster reads on semi-structured data". That release enabled the Parquet variant logical type and the shredding configurations by default (SPARK-54454), infers a shredding schema in the Parquet writer (SPARK-53659), reads the Parquet VARIANT logical type, and adds the colon operator for field access.[9] Spark 4.3.0 added functions that modify variant values (variant_set, variant_insert, variant_delete, variant_array_append, variant_strip_nulls), JSON_TABLE, and pushdown of variant_get filters to DataSource V2 sources.[10]

The main functions in Spark 4.3 are parse_json (parse a JSON string into a variant; try_parse_json returns null on invalid input), variant_get (extract a path and cast it to a type; try_variant_get returns null when the cast fails), schema_of_variant, is_variant_null, to_variant_object and the variant_explode generator.[11] The JSON, CSV and XML readers can also load each record into a single variant column with the singleVariantColumn option.[12]

The following Spark SQL query runs on Spark 4.3 and returns 42 and b:[11]

SELECT
  variant_get(v, '$.user.id', 'int')    AS user_id,
  variant_get(v, '$.tags[1]', 'string') AS second_tag
FROM (SELECT parse_json('{"user": {"id": 42}, "tags": ["a", "b"]}') AS v);

Apache Iceberg

The Iceberg table spec adds variant in format version 3, along with nanosecond timestamps, geometry, geography and unknown types.[3] The spec classes variant as a semi-structured type, neither primitive nor nested, and states that "the variant type and binary encoding are defined in the Parquet project, with support currently available for V1". In Parquet files Iceberg uses the Parquet VARIANT encoding and shredding; in Avro and ORC a variant is a record or struct with metadata and value fields. The spec also defines lower and upper bounds for fields inside a variant, keyed by normalized JSON path, and defines no 32-bit hash for variant because equal values can have several representations.[3]

In the Java implementation, Iceberg 1.9.0 added the variant type to core with Parquet variant readers and writers, and Iceberg 1.10.0 added variant read support for Spark Iceberg tables.[13][14]

Delta Lake

The Delta Lake protocol defines variant as the variantType table feature, which requires reader version 3 and writer version 7. Variant data is written to Parquet as a struct of two binaries, value and metadata, following the Parquet Variant binary encoding. A variant column cannot be a partition or clustering column, because variant is not a comparable type.[4] A separate variantShredding feature, which depends on variantType, allows shredded variants, and with it Delta can keep min and max statistics for variant columns.[4]

Delta Lake 4.0.0 made the variant type generally available (it was a preview in the Delta 4.0.0 preview release) and added shredded variants as a preview.[15] In Delta Lake 4.3.0 the variant shredding RFC was accepted into the protocol, and Delta Spark began collecting variant statistics on write.[16]

Support summary

Project Variant type Shredding Notes
Apache Parquet (format) Encoding spec and VARIANT logical type from 2.11.0[5] VariantShredding.md from 2.11.0[5] Home of the shared specification
Apache Spark 4.0.0[8] Writer infers shredding schema by default from 4.1.0[9] Implements a pinned commit of the Parquet spec; no UUID, Time or nanosecond timestamp values as of 4.3.0[2]
Apache Iceberg (spec) Format v3[3] Uses Parquet shredding[3] Variant v1 encoding
Apache Iceberg (Java) 1.9.0 (core and Parquet)[13]; 1.10.0 (Spark read)[14] Shredding fixes and Flink shredded writes listed in 1.11.0 and 1.12.0[17][18] Variant is a v3 type[3]
Delta Lake 4.0.0, variantType feature[15] Preview in 4.0.0[15]; RFC accepted in 4.3.0[16] Reader v3 / writer v7[4]

See also

References

  1. ↑ 1.0 1.1 1.2 1.3 Variant Binary Encoding (VariantEncoding.md, parquet-format 2.14.0). Apache Software Foundation.Retrieved 2026-11-22.
  2. ↑ 2.0 2.1 2.2 common/variant/README.md at v4.3.0. GitHub.Retrieved 2026-11-22.
  3. ↑ 3.0 3.1 3.2 3.3 3.4 3.5 Iceberg Table Spec: Semi-structured Types. Apache Software Foundation.Retrieved 2026-11-22.
  4. ↑ 4.0 4.1 4.2 4.3 Delta Transaction Log Protocol: Variant Data Type (PROTOCOL.md at v4.4.1). GitHub.Retrieved 2026-11-22.
  5. ↑ 5.0 5.1 5.2 5.3 Parquet Logical Type Definitions: VARIANT (parquet-format 2.11.0). Apache Software Foundation.Retrieved 2026-11-22.
  6. ↑ 6.0 6.1 Variant Shredding (VariantShredding.md, parquet-format 2.14.0). Apache Software Foundation.Retrieved 2026-11-22.
  7. ↑ Add the Variant Specification Docs (apache/parquet-format#455). GitHub.Retrieved 2026-11-22.
  8. ↑ 8.0 8.1 Spark Release 4.0.0. Apache Software Foundation.Retrieved 2026-11-22.
  9. ↑ 9.0 9.1 Spark Release 4.1.0. Apache Software Foundation.Retrieved 2026-11-22.
  10. ↑ Spark Release 4.3.0. Apache Software Foundation.Retrieved 2026-11-22.
  11. ↑ 11.0 11.1 Variant Functions (Spark SQL, Built-in Functions, 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  12. ↑ JSON Files (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  13. ↑ 13.0 13.1 Apache Iceberg 1.9.0. GitHub.Retrieved 2026-11-22.
  14. ↑ 14.0 14.1 Apache Iceberg 1.10.0. GitHub.Retrieved 2026-11-22.
  15. ↑ 15.0 15.1 15.2 Delta Lake 4.0.0. GitHub.Retrieved 2026-11-22.
  16. ↑ 16.0 16.1 Delta Lake 4.3.0. GitHub.Retrieved 2026-11-22.
  17. ↑ Apache Iceberg 1.11.0. GitHub.Retrieved 2026-11-22.
  18. ↑ Apache Iceberg 1.12.0. GitHub.Retrieved 2026-11-22.