apache/iceberg · error · IllegalStateException
Unknown type for int field. Type name:
Error message
Unknown type for int field. Type name:
What it means
StructRowData.getInt converts an Iceberg struct field value into a Flink int. It supports Integer, LocalDate (as epoch days) and LocalTime (as milliseconds since midnight); anything else is unexpected and thrown as an IllegalStateException naming the actual Java class. This indicates the in-memory value does not match the declared Iceberg int field type.
Solutions
- Check the actual class named in the message and align the writer so int fields contain Integer/LocalDate/LocalTime.
- Verify the Flink row type and the Iceberg schema agree on the field being an int (IntegerType vs LongType etc.).
- If you cannot fix the source data, wrap the read and convert the offending value yourself before it reaches StructRowData.
Example fix
// before: writer puts a long epoch-day value into an int DateType field row.setField(pos, someLong); // after: ensure the value is the expected class row.setField(pos, (int) someLong); // or LocalDate.ofEpochDay(someLong)
Defensive patterns
Strategy: type-guard
Validate before calling
// before reading
Object v = struct.getField(pos);
if (!(v instanceof Integer || v instanceof LocalDate || v instanceof LocalTime)) {
throw new IllegalArgumentException("Unexpected class for int field: " + v.getClass());
} Type guard
boolean isIntCompatible(Object v) {
return v instanceof Integer || v instanceof LocalDate || v instanceof LocalTime;
} Try / catch
try {
int value = rowData.getInt(pos);
} catch (IllegalStateException e) {
// log e.getMessage() which names the offending class; convert or skip the field
} Prevention
- Keep writer-side Java classes aligned with Iceberg primitive types (IntegerType -> Integer).
- Validate data classes in a unit test before jobs run.
- Watch for schema evolution that changes field types without rewriting data.
When it happens
Trigger: Calling getInt(pos) on a StructRowData whose underlying field object is not an Integer, LocalDate, or LocalTime, e.g. a Long/String/BigDecimal placed in an int-typed field.
Common situations: Reading data written by a writer that stored the wrong Java class in an IntegerType field; custom data models that keep dates/times as different types than the Flink converters expect; schema evolution changing a field type without rewriting values.
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 long field. Type name:
- errMsg(variant, "double")
- errMsg(variant, "int")
- errMsg(variant, "long")
- errMsg(variant, "timestamp")
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/c286e08b00fe7e60.
Report an issue: GitHub.
Appendix: source
Thrown at flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java:130
}
@Override
public short getShort(int pos) {
return (short) (int) struct.get(pos, Integer.class);
}
@Override
public int getInt(int pos) {
Object integer = struct.get(pos, Object.class);
if (integer instanceof Integer) {
return (int) integer;
} else if (integer instanceof LocalDate localDate) {
return (int) localDate.toEpochDay();
} else if (integer instanceof LocalTime) {
return (int) (((LocalTime) integer).toNanoOfDay() / 1000_000);
} else {
throw new IllegalStateException(
"Unknown type for int field. Type name: " + integer.getClass().getName());
}
}
@Override
public long getLong(int pos) {
Object longVal = struct.get(pos, 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 if (longVal instanceof LocalTime) {
return ((LocalTime) longVal).toNanoOfDay();
} else if (longVal instanceof LocalDateTime) {
return Duration.between(Instant.EPOCH, ((LocalDateTime) longVal).atOffset(ZoneOffset.UTC))View on GitHub (pinned to 86d9c8fc54)