{"record":{"id":"4b141b409de8c97b","repo":"apache/iceberg","slug":"cannot-convert-unsupported-type-to-spark-4b141b","errorCode":null,"errorMessage":"Cannot convert unsupported type to Spark: ","messagePattern":"Cannot convert unsupported type to Spark: ","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java","lineNumber":166,"sourceCode":"        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 GEOMETRY:\n        return geometryType((Types.GeometryType) primitive);\n      case GEOGRAPHY:\n        return geographyType((Types.GeographyType) primitive);\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 DataType geometryType(Types.GeometryType geometry) {\n    // The spec lets a geometry CRS be any string identifying a CRS, but Spark recognizes only a\n    // fixed set; a CRS Spark cannot resolve throws SparkIllegalArgumentException (an\n    // IllegalArgumentException).\n    return GeometryType$.MODULE$.apply(geometry.crs());\n  }\n\n  private DataType geographyType(Types.GeographyType geography) {\n    // The spec requires a geography CRS to be geographic; Spark recognizes only OGC:CRS84, so any\n    // other CRS throws SparkIllegalArgumentException (an IllegalArgumentException).\n    return GeographyType$.MODULE$.apply(geography.crs(), convertAlgorithm(geography.algorithm()));\n  }\n\n  // Translates Iceberg's edge-interpolation algorithm to Spark's. Spark supports only the spherical","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java#L148-L184","documentation":"Fallback in TypeToSparkType.primitive for Iceberg primitive types that have no Spark representation and no dedicated case. Indicates the schema contains a primitive the Spark converter does not recognize — usually a spec-version or runtime-version mismatch.","triggerScenarios":"Converting an Iceberg schema containing a primitive type added in a newer Iceberg spec than the Spark runtime supports, or a corrupt/unknown type id reaching the switch's default branch.","commonSituations":"Newer Iceberg writer produced a table read by an older Spark runtime jar; custom Type implementations leaking into conversion; mixed Iceberg versions on the classpath.","solutions":["Align the Iceberg Spark runtime version with the version that wrote the table","Inspect the offending field type (printed in the message) and rewrite it to a supported primitive","Check for duplicate/mixed Iceberg jars on the classpath"],"exampleFix":"// before\n// iceberg-spark-runtime 3.5_1.5.0 reading table written by 1.8.0 with new type\n// after\n// upgrade to iceberg-spark-runtime matching the writer version","handlingStrategy":"try-catch","validationCode":"table.schema().columns().forEach(c -> {\n  // ensure all primitives are standard spec types known to your runtime\n});","typeGuard":null,"tryCatchPattern":"try { spark.table(\"iceberg_table\").schema(); }\ncatch (UnsupportedOperationException e) {\n  if (e.getMessage().startsWith(\"Cannot convert unsupported type to Spark\")) { /* upgrade runtime */ }\n  else throw e;\n}","preventionTips":["Keep writer and reader Iceberg versions aligned","Avoid mixed Iceberg jars on the classpath","Review release notes for new type support before cross-version reads"],"tags":["spark","type-conversion","version-mismatch"],"backgroundTag":"type-mismatch","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"}