{"record":{"id":"f8186da3336a6eb5","repo":"apache/iceberg","slug":"unknown-type-for-int-field-type-name-classname","errorCode":null,"errorMessage":"Unknown type for int field. Type name: ${className}","messagePattern":"Unknown type for int field\\. Type name: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java","lineNumber":129,"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":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L111-L147","documentation":"StructRowData.getInt(pos) converts an Iceberg internal value at a field position into a Flink int. It accepts Integer, Short, Byte, LocalDate (epoch day), and LocalTime (millis of day); any other runtime class triggers IllegalStateException 'Unknown type for int field'.","triggerScenarios":"Reading a struct field whose stored value class does not match the projected Flink RowType's int field - e.g. a Long, String, or Temporal value where an int was expected due to a schema/type mismatch between the Iceberg schema and the Flink type.","commonSituations":"Mismatched FlinkSchema conversion (declared INT in Flink but Iceberg holds a long or date value); reading data written by a different writer version with different internal representations (e.g. LocalTime vs millis); custom readers producing unexpected value classes.","solutions":["Verify the Iceberg schema field is actually an int (Types.IntegerType) matching the Flink INT field; fix the schema mapping if not.","Log the offending class from the message and check which reader produced the value; use a reader that produces the expected representation.","Cast/convert the value in the custom reader (e.g. FlinkValueReaders) so ints are produced as Integer.","Align writer/reader Iceberg versions so internal value representations match."],"exampleFix":"// before: field declared INT but reader emits Long\nschema.add(\"v\", Types.LongType.get()); // Flink expects INT\n// after\nschema.add(\"v\", Types.IntegerType.get()); // matches StructRowData.getInt expectations","handlingStrategy":"type-guard","validationCode":"if (!(v instanceof Integer || v instanceof Short || v instanceof Byte || v instanceof LocalDate || v instanceof LocalTime)) {\n  throw new IllegalArgumentException(\"value not int-compatible: \" + v.getClass());\n}","typeGuard":"boolean isIntCompatible(Object v) {\n  return v instanceof Integer || v instanceof Short || v instanceof Byte\n      || v instanceof LocalDate || v instanceof LocalTime;\n}","tryCatchPattern":"try {\n  int i = structRow.getInt(pos);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Unknown type for int field\")) {\n    // fix schema mapping or convert value before projection\n  }\n}","preventionTips":["Keep Iceberg schema and Flink RowType in sync (IntegerType for INT)","Use the standard FlinkValueReaders so value classes match expectations","Pin consistent Iceberg versions between writer and reader jobs"],"tags":["flink","rowdata","type-mismatch","internal"],"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"}