apache/iceberg · error · IllegalStateException
Unknown type for int field. Type name: " + integer.getClass(
Error message
Unknown type for int field. Type name: " + integer.getClass().getName()
What it means
StructInternalRow.getInt extracts a Spark INTEGER/DATE int value from the underlying Iceberg struct field. It accepts Integer or LocalDate; any other stored Java type means the runtime object's class doesn't match the expected column type, so it throws IllegalStateException with the actual class name.
Source
Thrown at spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java:137
public byte getByte(int ordinal) {
return (byte) (int) struct.get(ordinal, Integer.class);
}
@Override
public short getShort(int ordinal) {
return (short) (int) struct.get(ordinal, Integer.class);
}
@Override
public int getInt(int ordinal) {
Object integer = struct.get(ordinal, Object.class);
if (integer instanceof Integer) {
return (int) integer;
} else if (integer instanceof LocalDate) {
return (int) ((LocalDate) integer).toEpochDay();
} else {
throw new IllegalStateException(
"Unknown type for int field. Type name: " + integer.getClass().getName());
}
}
@Override
public long getLong(int ordinal) {
Object longVal = struct.get(ordinal, Object.class);
if (longVal instanceof Long) {
return (long) longVal;
} else if (longVal instanceof OffsetDateTime) {
return Duration.between(Instant.EPOCH, (OffsetDateTime) longVal).toNanos() / 1000;
} else if (longVal instanceof LocalDate) {
return ((LocalDate) longVal).toEpochDay();
} else {
throw new IllegalStateException(
"Unknown type for long field. Type name: " + longVal.getClass().getName());
}View on GitHub (pinned to 86d9c8fc54)
Solutions
- Verify the expected Spark schema passed to the reader matches the actual Iceberg table schema for the int/date column
- Check what class is printed in the message and fix the code that produces that type (e.g. wrap/convert Long to Integer, or use getLong for Long columns)
- Update the Iceberg version if the underlying type-to-Java-class mapping changed for your type
- Rebuild any cached table metadata after schema evolution
Example fix
// before row.getInt(dateFieldOrdinal); // stored value is OffsetDateTime -> IllegalStateException // after // read the field with the accessor matching the actual stored type long epochDay = row.getLong(ordinal); // or fix the producer to store LocalDate/Integer
Defensive patterns
Strategy: type-guard
Validate before calling
Object v = struct.get(pos, javaClass);
if (!(v instanceof Integer) && !(v instanceof LocalDate)) {
throw new IllegalStateException("expected Integer/LocalDate for int field, got " + v.getClass());
} Type guard
boolean isIntBacked(Object v) { return v instanceof Integer || v instanceof LocalDate; } Try / catch
try { int i = row.getInt(ordinal); } catch (IllegalStateException e) { /* inspect e.getMessage() class name and fix the producer schema */ } Prevention
- Keep the expected Spark schema identical to the Iceberg table schema
- Run a one-time schema drift check between write and read paths
- Use Iceberg's standard conversions rather than custom struct wrappers
When it happens
Trigger: Reading a column whose Iceberg/Spark type mapping was wrong (e.g. the field actually holds Long, String, or BigDecimal) while Spark's expected schema declares an IntegerType/DateType at that ordinal — a struct-type/data mismatch between the provided schema and stored objects.
Common situations: Schema drift between table versions; supplying a wrong expected Spark schema in custom reads; custom Scan/GenericDataUtil conversions returning unexpected boxed types.
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
- Unknown type for int field. Type name: ${integer.getClass().
- Unknown type for long field. Type name: ${longVal.getClass()
- Unknown type for binary field. Type name: ${bytes.getClass()
- Unknown type for int field. Type name: + integer.getClass().
- Unknown type for long field. Type name: " + longVal.getClass
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/234b528481669787.
Report an issue: GitHub.