{"record":{"id":"604f58100b680e34","repo":"apache/iceberg","slug":"unsupported-binaryview-type","errorCode":null,"errorMessage":"Unsupported BinaryView type: ","messagePattern":"Unsupported BinaryView 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":394,"sourceCode":"            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) {\n    if (value instanceof Variant) {\n      Variant variant = (Variant) value;\n      byte[] metadataBytes = new byte[variant.metadata().sizeInBytes()];\n      ByteBuffer metadataBuffer = ByteBuffer.wrap(metadataBytes).order(ByteOrder.LITTLE_ENDIAN);\n      variant.metadata().writeTo(metadataBuffer, 0);\n\n      byte[] valueBytes = new byte[variant.value().sizeInBytes()];\n      ByteBuffer valueBuffer = ByteBuffer.wrap(valueBytes).order(ByteOrder.LITTLE_ENDIAN);\n      variant.value().writeTo(valueBuffer, 0);\n\n      return new VariantVal(valueBytes, metadataBytes);\n    }\n\n    throw new UnsupportedOperationException(\n        \"Unsupported value for VARIANT in StructInternalRow: \" + value.getClass());","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java#L376-L412","documentation":"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.","triggerScenarios":"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.","commonSituations":"Schema drift where a column was recreated as plain binary but read via spatial accessors; misconfigured type mapping between catalog schema and reader.","solutions":["Confirm the column's Iceberg type is geometry or geography in the table schema","Recreate/alter the column with the correct spatial type","Remove the spatial reader path for non-spatial binary columns"],"exampleFix":"// before: column defined as plain binary\n// after\nALTER TABLE t ALTER COLUMN geom SET TYPE geometry","handlingStrategy":"type-guard","validationCode":"if (!(colType instanceof Types.GeometryType) && !(colType instanceof Types.GeographyType)) {\n  throw new IllegalArgumentException(\"BinaryView conversion requires geometry/geography type\");\n}","typeGuard":"static boolean isSpatialBinaryView(Type t) {\n  return t instanceof Types.GeometryType || t instanceof Types.GeographyType;\n}","tryCatchPattern":"try {\n  Object g = row.getBinaryView(ordinal);\n} catch (UnsupportedOperationException e) {\n  g = readAsRawBinary(ordinal);\n}","preventionTips":["Verify column types with DESCRIBE TABLE before spatial reads","Avoid recreating spatial columns as plain binary","Keep spatial schema definitions in sync across writers"],"tags":["spark","geometry","wkb"],"backgroundTag":"incompatible-source-type","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}