apache/iceberg · error · UnsupportedOperationException

Variant column only supports getVariant()

Error message

Variant column only supports getVariant()

What it means

In Spark 4.2's VariantColumnVector, getBoolean(rowId) throws UnsupportedOperationException('Variant column only supports getVariant()'). Variant data must be decoded through the Variant API; boolean is just one of many accessor methods stubbed out to prevent misinterpretation of variant buffers.

Solutions

  1. Call getVariant(rowId) and extract the boolean via the Variant API after checking its type
  2. Make the read schema use VariantType for variant fields
  3. Remove or adjust casts of variant columns to boolean in the query
  4. Upgrade the consuming reader/connector to a variant-capable version

Example fix

// before
boolean b = columnVector.getBoolean(rowId);
// after
Variant v = ((VariantColumnVector) columnVector).getVariant(rowId);
boolean b = v.getType() == VariantUtil.Type.BOOLEAN ? ((VariantBoolean) v).get() : false;
Defensive patterns

Strategy: type-guard

Validate before calling

import org.apache.spark.sql.types.VariantType;
if (columnVector instanceof VariantColumnVector) { /* use getVariant */ }

Type guard

boolean isVariantColumn(ColumnVector v) { return v instanceof VariantColumnVector; }

Try / catch

try { b = vector.getBoolean(rowId); } catch (UnsupportedOperationException e) { if (e.getMessage().contains("getVariant()")) { b = extractBoolean(((VariantColumnVector) vector).getVariant(rowId)); } else throw e; }

Prevention

When it happens

Trigger: Calling getBoolean(rowId) on a variant-backed column, e.g. a reader whose expected schema declares BooleanType for a field that is variant, or generic vectorized code reading scalar columns positionally.

Common situations: Projection schema mismatched with table schema (boolean vs variant); custom data source readers predating variant support; queries casting variant to boolean in engines without variant-aware evaluation.

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/acaa467c1400329d. Report an issue: GitHub.

Appendix: source

Thrown at spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/data/vectorized/VariantColumnVector.java:80

    return valueChild.isNullAt(rowId);
  }

  // getChild is what getVariant() calls: child(0) = value, child(1) = metadata
  @Override
  public ColumnVector getChild(int ordinal) {
    if (ordinal == 0) {
      return valueChild;
    } else if (ordinal == 1) {
      return metadataChild;
    }

    throw new IllegalArgumentException(
        "Variant column has only 2 children, got ordinal: " + ordinal);
  }

  @Override
  public boolean getBoolean(int rowId) {
    throw unsupported();
  }

  @Override
  public byte getByte(int rowId) {
    throw unsupported();
  }

  @Override
  public short getShort(int rowId) {
    throw unsupported();
  }

  @Override
  public int getInt(int rowId) {
    throw unsupported();
  }

  @Override

View on GitHub (pinned to 86d9c8fc54)