apache/iceberg · error · UnsupportedOperationException
Cannot convert unsupported type to Spark:
Error message
Cannot convert unsupported type to Spark:
What it means
Fallback branch of TypeToSparkType.primitive: when an Iceberg primitive type has no mapping to a Spark type (any type not covered by the switch cases, e.g. unknown or future spec types), it throws UnsupportedOperationException with the type appended. UNKNOWN intentionally maps to NullType, so hitting this means a genuinely unmapped type was encountered.
Source
Thrown at spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java:131
} else {
return TimestampNTZType$.MODULE$;
}
case STRING:
return StringType$.MODULE$;
case UUID:
// use String
return StringType$.MODULE$;
case FIXED:
return BinaryType$.MODULE$;
case BINARY:
return BinaryType$.MODULE$;
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 Metadata fieldMetadata(int fieldId) {
if (MetadataColumns.metadataFieldIds().contains(fieldId)) {
return new MetadataBuilder().putBoolean(METADATA_COL_ATTR_KEY, true).build();
}
return Metadata.empty();
}
}
View on GitHub (pinned to 86d9c8fc54)
Solutions
- Align the Iceberg Spark runtime version with the version used to write the table (upgrade the connector)
- Check for mixed Iceberg jars on the classpath and remove stale versions
- Rewrite the column to a supported type in the table schema
Example fix
// before (pom.xml) <dependency>org.apache.iceberg:iceberg-spark-3.4_2.12:1.4.0</dependency> // after — match writer version <dependency>org.apache.iceberg:iceberg-spark-3.5_2.12:1.6.0</dependency>
Defensive patterns
Strategy: validation
Validate before calling
Schema schema = table.schema();
schema.columns().forEach(c -> {
if (!SUPPORTED_PRIMITIVES.contains(c.type().typeId())) {
throw new IllegalStateException("Unmapped Iceberg type: " + c.type());
}
}); Type guard
static boolean mappableToSpark(Type t) { return Set.of(BOOLEAN, INT, LONG, FLOAT, DOUBLE, DATE, TIMESTAMP, STRING, BINARY, DECIMAL, FIXED, UUID).contains(t.typeId()); } Try / catch
try { sparkType = TypeToSparkType.convert(icebergType); } catch (UnsupportedOperationException e) { throw new AnalysisException("Upgrade connector to read type: " + icebergType, e); } Prevention
- Keep writer and reader Iceberg versions aligned across engines
- Pin a single Iceberg version in your dependency management (BOM)
- Scan the classpath for duplicate org.apache.iceberg jars at startup
When it happens
Trigger: Converting an Iceberg schema containing a primitive type unknown to this connector version — typically a type introduced in a newer Iceberg spec being read by an older Spark connector.
Common situations: Iceberg library version mismatch between writer and reader (newer writer produces newer types); reading a table written by a newer Iceberg spec with an old connector jar on the classpath.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 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/3f2ea9ddc14c991f.
Report an issue: GitHub.