apache/iceberg · error · UnsupportedOperationException

Unsupported BinaryView type:

Error message

Unsupported BinaryView type: 

What it means

toBinaryView converts WKB binary values to Spark geometry/geography types. If the target Iceberg type is neither GeometryType nor GeographyType, it throws UnsupportedOperationException. Only spatial BinaryView columns are convertible via this path.

Solutions

  1. Confirm the column's Iceberg type is geometry or geography in the table schema
  2. Recreate/alter the column with the correct spatial type
  3. Remove the spatial reader path for non-spatial binary columns

Example fix

// before: column defined as plain binary
// after
ALTER TABLE t ALTER COLUMN geom SET TYPE geometry
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(colType instanceof Types.GeometryType) && !(colType instanceof Types.GeographyType)) {
  throw new IllegalArgumentException("BinaryView conversion requires geometry/geography type");
}

Type guard

static boolean isSpatialBinaryView(Type t) {
  return t instanceof Types.GeometryType || t instanceof Types.GeographyType;
}

Try / catch

try {
  Object g = row.getBinaryView(ordinal);
} catch (UnsupportedOperationException e) {
  g = readAsRawBinary(ordinal);
}

Prevention

When it happens

Trigger: Reading a binary column exposed as BinaryView whose declared type is not geometry/geography, e.g. a plain binary column or an unexpected custom BinaryView type.

Common situations: Schema drift where a column was recreated as plain binary but read via spatial accessors; misconfigured type mapping between catalog schema and reader.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java:394

            values,
            array -> (BiConsumer<Integer, Object>) (pos, v) -> array[pos] = toVariantVal(v));
      default:
        throw new UnsupportedOperationException("Unsupported array element type: " + elementType);
    }
  }

  private static BinaryView toBinaryView(Type type, byte[] wkb) {
    return toBinaryView(SparkSchemaUtil.convert(type), wkb);
  }

  private static BinaryView toBinaryView(DataType type, byte[] wkb) {
    if (type instanceof GeometryType) {
      return STUtils.stGeomFromWKB(wkb, ((GeometryType) type).srid());
    } else if (type instanceof GeographyType) {
      return STUtils.stGeogFromWKB(wkb, ((GeographyType) type).srid());
    }

    throw new UnsupportedOperationException("Unsupported BinaryView type: " + type);
  }

  private static VariantVal toVariantVal(Object value) {
    if (value instanceof Variant) {
      Variant variant = (Variant) value;
      byte[] metadataBytes = new byte[variant.metadata().sizeInBytes()];
      ByteBuffer metadataBuffer = ByteBuffer.wrap(metadataBytes).order(ByteOrder.LITTLE_ENDIAN);
      variant.metadata().writeTo(metadataBuffer, 0);

      byte[] valueBytes = new byte[variant.value().sizeInBytes()];
      ByteBuffer valueBuffer = ByteBuffer.wrap(valueBytes).order(ByteOrder.LITTLE_ENDIAN);
      variant.value().writeTo(valueBuffer, 0);

      return new VariantVal(valueBytes, metadataBytes);
    }

    throw new UnsupportedOperationException(
        "Unsupported value for VARIANT in StructInternalRow: " + value.getClass());

View on GitHub (pinned to 86d9c8fc54)