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 reads the Iceberg StructLike value and only knows how to convert Integer and LocalDate instances. If the underlying stored object is any other type (e.g. Timestamp, LocalDateTime, or a boxed mismatch from a custom reader), it throws IllegalStateException naming the actual Java class found.

Source

Thrown at spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java:131

  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

  1. Check the table schema and confirm the column's Iceberg type matches the expected value (DateType -> LocalDate, IntegerType -> Integer)
  2. Inspect the type name in the message to identify which producer is emitting the wrong object class
  3. Fix the reader/mapping code that populates the StructLike so int-typed fields hold Integer or LocalDate
  4. If in a custom path, widen your conversion before calling getInt

Example fix

// before
int v = row.getInt(ordinal); // value is LocalDateTime
// after
Object raw = row.get(ordinal, null);
int v = raw instanceof LocalDateTime
    ? (int) ((LocalDateTime) raw).toLocalDate().toEpochDay()
    : row.getInt(ordinal);
Defensive patterns

Strategy: type-guard

Validate before calling

Object v = row.get(ordinal, null);
if (!(v instanceof Integer) && !(v instanceof LocalDate)) {
  throw new IllegalStateException("Unexpected int-field value: " + v.getClass());
}

Type guard

boolean isIntCompatible(Object v) { return v instanceof Integer || v instanceof LocalDate; }

Try / catch

try {
  return row.getInt(ordinal);
} catch (IllegalStateException e) {
  throw new IllegalStateException("Int field held unexpected Java type; check reader/producer mapping", e);
}

Prevention

When it happens

Trigger: Iceberg column of date/int type whose StructLike value is not an Integer or LocalDate — typically when Spark type mapping disagrees with the physical value type, or a custom data source supplies unexpected objects.

Common situations: Schema drift between table metadata and actual stored objects; custom TypeToSparkType mapping mismatch; bugs in custom readers producing LocalDateTime for a date field.

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


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/bec9c83dfc6bedd8. Report an issue: GitHub.