apache/iceberg · error · UnsupportedOperationException

Avro writer does not support variant types

Error message

Avro writer does not support variant types

What it means

ParquetAvroWriter converts Parquet schemas into ParquetValueWriters for writing Avro data to Parquet files. Variant types (Parquet's semi-structured Variant logical type) have no Avro representation in this writer, so the library deliberately rejects them at write-planning time rather than silently corrupting data.

Source

Thrown at parquet/src/main/java/org/apache/iceberg/parquet/ParquetAvroWriter.java:108

      int repeatedD = type.getMaxDefinitionLevel(repeatedPath);
      int repeatedR = type.getMaxRepetitionLevel(repeatedPath);

      Type keyType = repeatedKeyValue.getType(0);
      int keyD = type.getMaxDefinitionLevel(path(keyType.getName()));
      Type valueType = repeatedKeyValue.getType(1);
      int valueD = type.getMaxDefinitionLevel(path(valueType.getName()));

      return ParquetValueWriters.maps(
          repeatedD,
          repeatedR,
          ParquetValueWriters.option(keyType, keyD, keyWriter),
          ParquetValueWriters.option(valueType, valueD, valueWriter));
    }

    @Override
    public ParquetValueWriter<?> variant(GroupType variant) {
      throw new UnsupportedOperationException("Avro writer does not support variant types");
    }

    @Override
    public ParquetValueWriter<?> primitive(PrimitiveType primitive) {
      ColumnDescriptor desc = type.getColumnDescription(currentPath());

      if (primitive.getOriginalType() != null) {
        switch (primitive.getOriginalType()) {
          case ENUM:
          case JSON:
          case UTF8:
            return ParquetValueWriters.strings(desc);
          case DATE:
          case INT_8:
          case INT_16:
          case INT_32:
            return ParquetValueWriters.ints(desc);
          case INT_64:

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Remove the variant column from the data being written or write it as a supported type (e.g., string/JSON bytes)
  2. Use a different Parquet writer that supports variants (e.g., the Iceberg internal/GenericParquetWriter path)
  3. Pin/downgrade the table schema so variant columns are not present, or use format-version 2 tables without variant fields

Example fix

// before: schema contains Variant type 'v'
ParquetAvroWriter<?> writer = ParquetAvro.write(fileSchema).build();
// after: exclude or convert variant before writing
Schema withoutVariant = new Schema(schema.columns().stream()
    .filter(c -> !c.transform().equals(Types.VariantType.get()))
    .collect(Collectors.toList()));
Defensive patterns

Strategy: validation

Validate before calling

boolean hasVariant = schema.columns().stream().anyMatch(c -> c.type().typeId() == Type.TypeID.VARIANT);
if (hasVariant) throw new IllegalArgumentException("Variant columns unsupported for Avro Parquet writes");

Type guard

static boolean isVariantType(Type t) { return t != null && t.typeId() == Type.TypeID.VARIANT; }

Prevention

When it happens

Trigger: Writing a Parquet schema that contains a Variant group type via the Avro-backed Parquet writer (ParquetAvro.buildWriter); the variant() visitor method is invoked during schema conversion.

Common situations: A table gains a variant column (Iceberg v3 feature) while the pipeline still writes with the Avro writer path; users assume Avro support parity with the generic/Spark writers.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/f5a59bdc0426569d. Report an issue: GitHub.