{"record":{"id":"b01b5e112e161887","repo":"apache/iceberg","slug":"unknown-type-for-int-field-type-name-integer-g-b01b5e","errorCode":null,"errorMessage":"Unknown type for int field. Type name: + integer.getClass().getName()","messagePattern":"Unknown type for int field\\. Type name: \\+ integer\\.getClass\\(\\)\\.getName\\(\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java","lineNumber":135,"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":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java#L117-L153","documentation":"StructInternalRow.getInt converts the stored field value to a Spark int, accepting Integer or LocalDate (Iceberg Date). If the stored object is neither (a data/spec mismatch between the Iceberg type and what was stored), it throws IllegalStateException naming the actual class.","triggerScenarios":"Calling getInt(ordinal) on a StructInternalRow whose underlying struct field holds an object that is not Integer or LocalDate, e.g. a long-backed timestamp stored where an int-typed (Date) column was expected.","commonSituations":"Schema evolution changing a column type without rewriting data; reading Date data where the struct actually stores a different Java representation; type-promotion mismatches between table schema and read schema.","solutions":["Check the stored type named in the message and read the field with the matching getter (getLong for long-backed types)","Align the requested Spark type with the Iceberg schema (Date -> int, Timestamp -> long)","Rewrite data or refresh metadata if the physical type drifted from the declared schema"],"exampleFix":"// before\nint v = structRow.getInt(dateOrdinal); // stores OffsetDateTime\n// after\nlong epochDayMicros = structRow.getLong(dateOrdinal); // match stored representation","handlingStrategy":"type-guard","validationCode":"Object v = structLike.get(ordinal, null);\nif (!(v instanceof Integer || v instanceof LocalDate)) {\n  throw new IllegalArgumentException(\"Field \" + ordinal + \" is not int-compatible: \" + v.getClass());\n}","typeGuard":"boolean isIntField(Object v) { return v instanceof Integer || v instanceof LocalDate; }","tryCatchPattern":"try {\n  return row.getInt(ordinal);\n} catch (IllegalStateException e) {\n  // fall back to getLong/conversion based on the stored type\n}","preventionTips":["Match getters to the Iceberg type: Date -> getInt, Timestamp/Long -> getLong","Re-check schemas after type promotion or evolution operations","Log stored field classes when debugging struct reads"],"tags":["type-mismatch","spark","internal-row","int"],"backgroundTag":"type-mismatch","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}