{"record":{"id":"bec9c83dfc6bedd8","repo":"apache/iceberg","slug":"unknown-type-for-int-field-type-name-integer-g-bec9c8","errorCode":null,"errorMessage":"Unknown type for int field. Type name: ${integer.getClass().getName()}","messagePattern":"Unknown type for int field\\. Type name: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java","lineNumber":131,"sourceCode":"  public byte getByte(int ordinal) {\n    return (byte) (int) struct.get(ordinal, Integer.class);\n  }\n\n  @Override\n  public short getShort(int ordinal) {\n    return (short) (int) struct.get(ordinal, Integer.class);\n  }\n\n  @Override\n  public int getInt(int ordinal) {\n    Object integer = struct.get(ordinal, Object.class);\n\n    if (integer instanceof Integer) {\n      return (int) integer;\n    } else if (integer instanceof LocalDate) {\n      return (int) ((LocalDate) integer).toEpochDay();\n    } else {\n      throw new IllegalStateException(\n          \"Unknown type for int field. Type name: \" + integer.getClass().getName());\n    }\n  }\n\n  @Override\n  public long getLong(int ordinal) {\n    Object longVal = struct.get(ordinal, Object.class);\n\n    if (longVal instanceof Long) {\n      return (long) longVal;\n    } else if (longVal instanceof OffsetDateTime) {\n      return Duration.between(Instant.EPOCH, (OffsetDateTime) longVal).toNanos() / 1000;\n    } else if (longVal instanceof LocalDate) {\n      return ((LocalDate) longVal).toEpochDay();\n    } else {\n      throw new IllegalStateException(\n          \"Unknown type for long field. Type name: \" + longVal.getClass().getName());\n    }","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java#L113-L149","documentation":"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.","triggerScenarios":"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.","commonSituations":"Schema drift between table metadata and actual stored objects; custom TypeToSparkType mapping mismatch; bugs in custom readers producing LocalDateTime for a date field.","solutions":["Check the table schema and confirm the column's Iceberg type matches the expected value (DateType -> LocalDate, IntegerType -> Integer)","Inspect the type name in the message to identify which producer is emitting the wrong object class","Fix the reader/mapping code that populates the StructLike so int-typed fields hold Integer or LocalDate","If in a custom path, widen your conversion before calling getInt"],"exampleFix":"// before\nint v = row.getInt(ordinal); // value is LocalDateTime\n// after\nObject raw = row.get(ordinal, null);\nint v = raw instanceof LocalDateTime\n    ? (int) ((LocalDateTime) raw).toLocalDate().toEpochDay()\n    : row.getInt(ordinal);","handlingStrategy":"type-guard","validationCode":"Object v = row.get(ordinal, null);\nif (!(v instanceof Integer) && !(v instanceof LocalDate)) {\n  throw new IllegalStateException(\"Unexpected int-field value: \" + v.getClass());\n}","typeGuard":"boolean isIntCompatible(Object v) { return v instanceof Integer || v instanceof LocalDate; }","tryCatchPattern":"try {\n  return row.getInt(ordinal);\n} catch (IllegalStateException e) {\n  throw new IllegalStateException(\"Int field held unexpected Java type; check reader/producer mapping\", e);\n}","preventionTips":["Keep producers aligned with declared Iceberg types","Log the offending class name from the message","Test custom readers with all schema types"],"tags":["spark","type-mismatch","illegal-state","internalrow"],"backgroundTag":"type-mismatch","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}