apache/iceberg · error · IllegalArgumentException
Unsupported type: {primitive}
Error message
Unsupported type: {primitive} What it means
SparkAvroWriter's primitive() maps Avro primitive types to value writers; the default branch is unreachable for valid Avro primitives but guards against unknown/unexpected primitive enum values, throwing IllegalArgumentException. It indicates the Avro schema contains a primitive the writer cannot handle.
Source
Thrown at spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/data/SparkAvroWriter.java:171
return ValueWriters.tinyints();
} else if (type instanceof ShortType) {
return ValueWriters.shorts();
}
return ValueWriters.ints();
case LONG:
return ValueWriters.longs();
case FLOAT:
return ValueWriters.floats();
case DOUBLE:
return ValueWriters.doubles();
case STRING:
return SparkValueWriters.strings();
case FIXED:
return ValueWriters.fixed(primitive.getFixedSize());
case BYTES:
return ValueWriters.bytes();
default:
throw new IllegalArgumentException("Unsupported type: " + primitive);
}
}
}
}
View on GitHub (pinned to 86d9c8fc54)
Solutions
- Validate the Avro schema against the standard primitive set before writing
- Upgrade Iceberg for newer Avro primitive support
- Remap the field to a supported primitive type (e.g. BYTES/FIXED)
- Check that the schema was not hand-edited or generated incorrectly
Defensive patterns
Strategy: type-guard
Validate before calling
Set<Schema.Type> allowed = Set.of(STRING, INT, LONG, FLOAT, DOUBLE, BOOLEAN, FIXED, BYTES, NULL);
avroSchema.getFields().forEach(f -> {
if (f.schema().getType() == Schema.Type.UNION) {
f.schema().getTypes().forEach(t -> Preconditions.checkArgument(allowed.contains(t.getType()), t.getType()));
} else Preconditions.checkArgument(allowed.contains(f.schema().getType()), f.schema().getType());
}); Type guard
boolean supportedPrimitive(org.apache.avro.Schema s) {
return s.getType() != UNION || s.getTypes().stream().allMatch(t -> t.getType() != UNION && isKnown(t));
} Try / catch
try {
writer.write(row);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unsupported type")) { /* sanitize the Avro schema */ }
else throw e;
} Prevention
- Validate Avro schemas before writing
- Use standard Avro primitives only
- Keep the Avro library and Iceberg versions in sync
When it happens
Trigger: Encountering an Avro primitive type outside the handled set (STRING, INT, LONG, FLOAT, DOUBLE, BOOLEAN, FIXED, BYTES, NULL) — typically only possible with a corrupted or non-standard schema, or a future Avro primitive type.
Common situations: Schema parsing anomalies from hand-written Avro schemas; forward-compatibility issues with newer Avro libraries introducing new primitives.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unsupported logical type: ${logicalType}
- Unsupported type: ${primitive}
- Unsupported type: %s
- Unsupported logical type:
- Unsupported type:
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/21cbd9d25f71dcff.
Report an issue: GitHub.