{"record":{"id":"b0510083dfeaaca5","repo":"apache/iceberg","slug":"unsupported-array-element-type","errorCode":null,"errorMessage":"Unsupported array element type: ","messagePattern":"Unsupported array element type: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java","lineNumber":379,"sourceCode":"        return fillArray(\n            values,\n            array ->\n                (BiConsumer<Integer, Collection<?>>)\n                    (pos, list) ->\n                        array[pos] =\n                            collectionToArrayData(elementType.asListType().elementType(), list));\n      case MAP:\n        return fillArray(\n            values,\n            array ->\n                (BiConsumer<Integer, Map<?, ?>>)\n                    (pos, map) -> array[pos] = mapToMapData(elementType.asMapType(), map));\n      case VARIANT:\n        return fillArray(\n            values,\n            array -> (BiConsumer<Integer, Object>) (pos, v) -> array[pos] = toVariantVal(v));\n      default:\n        throw new UnsupportedOperationException(\"Unsupported array element type: \" + elementType);\n    }\n  }\n\n  private static BinaryView toBinaryView(Type type, byte[] wkb) {\n    return toBinaryView(SparkSchemaUtil.convert(type), wkb);\n  }\n\n  private static BinaryView toBinaryView(DataType type, byte[] wkb) {\n    if (type instanceof GeometryType) {\n      return STUtils.stGeomFromWKB(wkb, ((GeometryType) type).srid());\n    } else if (type instanceof GeographyType) {\n      return STUtils.stGeogFromWKB(wkb, ((GeographyType) type).srid());\n    }\n\n    throw new UnsupportedOperationException(\"Unsupported BinaryView type: \" + type);\n  }\n\n  private static VariantVal toVariantVal(Object value) {","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java#L361-L397","documentation":"collectionToArrayData converts a collection of Iceberg values into Spark's ArrayData but only handles a fixed set of element types; any other Iceberg element type hits the default branch and throws UnsupportedOperationException with the type name. The conversion layer simply has no mapping for that element type yet.","triggerScenarios":"Reading a nested array column whose element type falls outside the supported switch cases (e.g. certain complex or newer types) through StructInternalRow's array accessor.","commonSituations":"Tables using newer or nested types (variant-like, custom geometry element types) inside arrays read via the Spark 4.2 row reader; version skew where writer produced types the reader cannot convert.","solutions":["Flatten or cast the array element to a supported type (string, struct of primitives) in the query","Exclude the unsupported nested column from the projection","Upgrade Iceberg/Spark integration where more element types may be supported"],"exampleFix":"// before\nSELECT arr FROM t  -- arr: array<variant>\n// after\nSELECT transform(arr, x -> to_json(x)) AS arr FROM t","handlingStrategy":"validation","validationCode":"if (!SUPPORTED_ELEMENT_TYPES.contains(arrayType.elementType())) {\n  throw new IllegalArgumentException(\"Unsupported array element: \" + arrayType.elementType());\n}","typeGuard":"static boolean hasSupportedArrayElementType(Types.NestedField f) {\n  return f.type().isListType() &&\n    !(f.type().asListType().elementType() instanceof Types.VariantType);\n}","tryCatchPattern":"try {\n  ArrayData arr = row.getArray(ordinal);\n} catch (UnsupportedOperationException e) {\n  arr = readAsJson(ordinal);\n}","preventionTips":["Check the reader's supported nested-type matrix before adding new array element types","Keep writer/reader versions consistent","Prefer primitive element types in arrays"],"tags":["spark","array","unsupported-type"],"backgroundTag":"unsupported-enum-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}