{"record":{"id":"c4dccf028b5bc325","repo":"apache/iceberg","slug":"unknown-type-for-int-field-type-name-integer","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":"flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java","lineNumber":130,"sourceCode":"  }\n\n  @Override\n  public short getShort(int pos) {\n    return (short) (int) struct.get(pos, Integer.class);\n  }\n\n  @Override\n  public int getInt(int pos) {\n    Object integer = struct.get(pos, Object.class);\n\n    if (integer instanceof Integer) {\n      return (int) integer;\n    } else if (integer instanceof LocalDate localDate) {\n      return (int) localDate.toEpochDay();\n    } else if (integer instanceof LocalTime) {\n      return (int) (((LocalTime) integer).toNanoOfDay() / 1000_000);\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 pos) {\n    Object longVal = struct.get(pos, 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 if (longVal instanceof LocalTime) {\n      return ((LocalTime) longVal).toNanoOfDay();\n    } else if (longVal instanceof LocalDateTime) {\n      return Duration.between(Instant.EPOCH, ((LocalDateTime) longVal).atOffset(ZoneOffset.UTC))","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L112-L148","documentation":"StructRowData.getInt converts the Object stored in the wrapped Iceberg StructLike at pos into a Flink INT. It accepts Integer, LocalDate (Date field, converted to epoch day) and LocalTime (Time field, converted to millisecond-of-day); any other runtime type means the struct holds a value inconsistent with an int-typed field and IllegalStateException is thrown with the actual class name.","triggerScenarios":"Reading a projected/int column via StructRowData.getInt(pos) when the underlying StructLike stores something other than Integer/LocalDate/LocalTime — e.g. a Long or String written by a custom writer or an incompatible schema at read time.","commonSituations":"Schema drift between the table schema used to write the data and the schema supplied when reading; custom StructLike implementations (e.g. wrapped GenericRecord or Row) storing boxed types outside the expected set; reading Date/Time columns whose backing representation changed across Iceberg versions.","solutions":["Verify the Iceberg schema passed to StructRowData matches the actual types of the underlying StructLike data; re-align field positions/types.","Check what class the error names — the message prints the actual stored type; fix the writer/reader so an int field stores Integer, LocalDate or LocalTime.","If reading files written by another engine/version, rewrite or re-read with the schema the files were written with.","Wrap getInt with a pre-check: struct.get(pos, Object.class) type inspection before calling, converting unsupported types explicitly."],"exampleFix":"// before\nint v = structRowData.getInt(pos); // IllegalStateException for unexpected type\n\n// after\nObject raw = struct.get(pos, Object.class);\nint v;\nif (raw instanceof Integer i) {\n  v = i;\n} else if (raw instanceof Long l) {\n  v = Math.toIntExact(l);\n} else if (raw instanceof String s) {\n  v = Integer.parseInt(s);\n} else {\n  v = structRowData.getInt(pos);\n}","handlingStrategy":"validation","validationCode":"Object raw = struct.get(pos, Object.class);\nPreconditions.checkArgument(\n    raw == null || raw instanceof Integer || raw instanceof LocalDate || raw instanceof LocalTime,\n    \"int field holds unexpected type: %s\", raw == null ? \"null\" : raw.getClass());","typeGuard":"boolean isIntRepresentable(Object v) {\n  return v instanceof Integer || v instanceof LocalDate || v instanceof LocalTime;\n}","tryCatchPattern":"try {\n  int v = structRowData.getInt(pos);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Unknown type for int field\")) {\n    log.error(\"Schema mismatch on int column at pos {}\", pos, e);\n    throw new SchemaMismatchException(e);\n  }\n  throw e;\n}","preventionTips":["Keep the read schema identical to the write schema; validate with a schema-compat check at job start.","Unit-test StructLike producers so int/date/time fields store Integer/LocalDate/LocalTime."],"tags":["flink","structlike","type-mismatch","schema-drift"],"backgroundTag":"type-mismatch","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}