apache/iceberg · error · UnsupportedOperationException

Unsupported array element type: " + elementType

Error message

Unsupported array element type: " + elementType

What it means

collectionToArrayData converts a collection of Iceberg values into a Spark ArrayData during column pruning/conversion. When the array's element Type is a Type Iceberg cannot map to Spark ArrayData (not in the handled cases), it throws UnsupportedOperationException naming the element type.

Solutions

  1. Check the actual element type reported in the message and confirm it is a supported Iceberg type for your Spark version
  2. Rewrite/re-serialize the column to a supported element type in the table
  3. Upgrade the Iceberg Spark runtime to a version supporting that element type
  4. Cast the column in SQL to a supported type in the read query

Example fix

// before
SELECT unsupported_arr FROM iceberg_table
// after
SELECT transform(unsupported_arr, x -> cast(x as string)) AS arr FROM iceberg_table
Defensive patterns

Strategy: validation

Validate before calling

if (Arrays.stream(schema.fields()).anyMatch(f ->
    f.dataType() instanceof ArrayType && !isSupportedElementType((ArrayType) f.dataType()))) {
  log.warn("Array element type not supported by StructInternalRow; cast or filter it out");
}

Type guard

static boolean isSupportedElementType(ArrayType t) {
  return !(t.elementType() instanceof CalendarIntervalType);
}

Try / catch

try { readArrayColumn(); } catch (UnsupportedOperationException e) {
  log.error("Unsupported array element type: {}", e.getMessage(), e);
  // fall back to reading the column as string
}

Prevention

When it happens

Trigger: Reading an Iceberg table column whose array element type is not one of the supported mappings (e.g. nested or exotic types reaching the default branch of collectionToArrayData).

Common situations: Reading tables written with newer or non-Spark writers containing array element types the Spark 4.1 integration doesn't map; mismatched schema assumptions after format version upgrades.

Related errors


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

Appendix: source

Thrown at spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java:368

        return fillArray(
            values,
            array ->
                (BiConsumer<Integer, Collection<?>>)
                    (pos, list) ->
                        array[pos] =
                            collectionToArrayData(elementType.asListType().elementType(), list));
      case MAP:
        return fillArray(
            values,
            array ->
                (BiConsumer<Integer, Map<?, ?>>)
                    (pos, map) -> array[pos] = mapToMapData(elementType.asMapType(), map));
      case VARIANT:
        return fillArray(
            values,
            array -> (BiConsumer<Integer, Object>) (pos, v) -> array[pos] = toVariantVal(v));
      default:
        throw new UnsupportedOperationException("Unsupported array element type: " + elementType);
    }
  }

  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(

View on GitHub (pinned to 86d9c8fc54)