apache/iceberg · error · java.lang.UnsupportedOperationException
Cannot convert unsupported type to Spark:
Error message
Cannot convert unsupported type to Spark:
What it means
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.
Source
Thrown at spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java:166
return StringType$.MODULE$;
case UUID:
// use String
return StringType$.MODULE$;
case FIXED:
return BinaryType$.MODULE$;
case BINARY:
return BinaryType$.MODULE$;
case GEOMETRY:
return geometryType((Types.GeometryType) primitive);
case GEOGRAPHY:
return geographyType((Types.GeographyType) primitive);
case DECIMAL:
Types.DecimalType decimal = (Types.DecimalType) primitive;
return DecimalType$.MODULE$.apply(decimal.precision(), decimal.scale());
case UNKNOWN:
return NullType$.MODULE$;
default:
throw new UnsupportedOperationException(
"Cannot convert unsupported type to Spark: " + primitive);
}
}
private DataType geometryType(Types.GeometryType geometry) {
// The spec lets a geometry CRS be any string identifying a CRS, but Spark recognizes only a
// fixed set; a CRS Spark cannot resolve throws SparkIllegalArgumentException (an
// IllegalArgumentException).
return GeometryType$.MODULE$.apply(geometry.crs());
}
private DataType geographyType(Types.GeographyType geography) {
// The spec requires a geography CRS to be geographic; Spark recognizes only OGC:CRS84, so any
// other CRS throws SparkIllegalArgumentException (an IllegalArgumentException).
return GeographyType$.MODULE$.apply(geography.crs(), convertAlgorithm(geography.algorithm()));
}
// Translates Iceberg's edge-interpolation algorithm to Spark's. Spark supports only the sphericalView on GitHub (pinned to 86d9c8fc54)
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
Example fix
// before // iceberg-spark-runtime 3.5_1.5.0 reading table written by 1.8.0 with new type // after // upgrade to iceberg-spark-runtime matching the writer version
Defensive patterns
Strategy: try-catch
Validate before calling
table.schema().columns().forEach(c -> {
// ensure all primitives are standard spec types known to your runtime
}); Try / catch
try { spark.table("iceberg_table").schema(); }
catch (UnsupportedOperationException e) {
if (e.getMessage().startsWith("Cannot convert unsupported type to Spark")) { /* upgrade runtime */ }
else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot convert unsupported type to Spark:
- Cannot convert unknown type to Flink: %s
- Not a supported type: type
- Spark does not support time fields
- Unknown manifest content:
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/4b141b409de8c97b.
Report an issue: GitHub.