{"record":{"id":"56da917ccfc2e105","repo":"apache/iceberg","slug":"cannot-convert-unsupported-type-to-spark-primit","errorCode":null,"errorMessage":"Cannot convert unsupported type to Spark: ${primitive}","messagePattern":"Cannot convert unsupported type to Spark: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java","lineNumber":154,"sourceCode":"        } else {\n          return TimestampNTZType$.MODULE$;\n        }\n      case STRING:\n        return StringType$.MODULE$;\n      case UUID:\n        // use String\n        return StringType$.MODULE$;\n      case FIXED:\n        return BinaryType$.MODULE$;\n      case BINARY:\n        return BinaryType$.MODULE$;\n      case DECIMAL:\n        Types.DecimalType decimal = (Types.DecimalType) primitive;\n        return DecimalType$.MODULE$.apply(decimal.precision(), decimal.scale());\n      case UNKNOWN:\n        return NullType$.MODULE$;\n      default:\n        throw new UnsupportedOperationException(\n            \"Cannot convert unsupported type to Spark: \" + primitive);\n    }\n  }\n\n  private Metadata fieldMetadata(int fieldId) {\n    if (MetadataColumns.metadataFieldIds().contains(fieldId)) {\n      return new MetadataBuilder().putBoolean(METADATA_COL_ATTR_KEY, true).build();\n    }\n\n    return Metadata.empty();\n  }\n}\n","sourceCodeStart":136,"sourceCodeEnd":167,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java#L136-L167","documentation":"The primitive() method in TypeToSparkType throws UnsupportedOperationException when it encounters an Iceberg primitive type it has no mapping for, listing the offending type in the message. It is a catch-all for type system drift between Iceberg and Spark.","triggerScenarios":"Converting an Iceberg schema to a Spark schema where a primitive is not covered by the switch (anything besides boolean/int/long/float/double/date/time/timestamp/string/binary/decimal/uuid/unknown in unhandled versions).","commonSituations":"Tables written with a newer Iceberg spec type being read by an older iceberg-spark runtime; custom primitive extensions.","solutions":["Upgrade the iceberg-spark runtime to a version that supports the type","Inspect the schema (table.schema()) and remove/migrate unsupported column types","If the type is newly added to Iceberg, add a case in TypeToSparkType.primitive"],"exampleFix":"// before\ndefault: throw new UnsupportedOperationException(\"Cannot convert unsupported type to Spark: \" + primitive);\n// after\ncase UUID: return StringType$.MODULE$;\ndefault: throw new UnsupportedOperationException(\"Cannot convert unsupported type to Spark: \" + primitive);","handlingStrategy":"try-catch","validationCode":"for (Types.NestedField f : table.schema().columns()) { SparkSchemaUtil.convert(f.type()); } // throws early if unsupported","typeGuard":null,"tryCatchPattern":"try { Schema spark = SparkSchemaUtil.convert(icebergSchema); } catch (UnsupportedOperationException e) { /* inspect e.getMessage() for the offending primitive and remap it */ }","preventionTips":["Upgrade the Spark runtime before adopting tables written with newer Iceberg types","Validate schema convertibility with SparkSchemaUtil.convert during migrations"],"tags":["spark","type-conversion","unsupported-type","schema"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}