{"record":{"id":"c286e08b00fe7e60","repo":"apache/iceberg","slug":"unknown-type-for-int-field-type-name","errorCode":null,"errorMessage":"Unknown type for int field. Type name: ","messagePattern":"Unknown type for int field\\. Type name: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/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.3/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L112-L148","documentation":"StructRowData.getInt converts an Iceberg struct field value into a Flink int. It supports Integer, LocalDate (as epoch days) and LocalTime (as milliseconds since midnight); anything else is unexpected and thrown as an IllegalStateException naming the actual Java class. This indicates the in-memory value does not match the declared Iceberg int field type.","triggerScenarios":"Calling getInt(pos) on a StructRowData whose underlying field object is not an Integer, LocalDate, or LocalTime, e.g. a Long/String/BigDecimal placed in an int-typed field.","commonSituations":"Reading data written by a writer that stored the wrong Java class in an IntegerType field; custom data models that keep dates/times as different types than the Flink converters expect; schema evolution changing a field type without rewriting values.","solutions":["Check the actual class named in the message and align the writer so int fields contain Integer/LocalDate/LocalTime.","Verify the Flink row type and the Iceberg schema agree on the field being an int (IntegerType vs LongType etc.).","If you cannot fix the source data, wrap the read and convert the offending value yourself before it reaches StructRowData."],"exampleFix":"// before: writer puts a long epoch-day value into an int DateType field\nrow.setField(pos, someLong);\n\n// after: ensure the value is the expected class\nrow.setField(pos, (int) someLong); // or LocalDate.ofEpochDay(someLong)","handlingStrategy":"type-guard","validationCode":"// before reading\nObject v = struct.getField(pos);\nif (!(v instanceof Integer || v instanceof LocalDate || v instanceof LocalTime)) {\n  throw new IllegalArgumentException(\"Unexpected class for int field: \" + v.getClass());\n}","typeGuard":"boolean isIntCompatible(Object v) {\n  return v instanceof Integer || v instanceof LocalDate || v instanceof LocalTime;\n}","tryCatchPattern":"try {\n  int value = rowData.getInt(pos);\n} catch (IllegalStateException e) {\n  // log e.getMessage() which names the offending class; convert or skip the field\n}","preventionTips":["Keep writer-side Java classes aligned with Iceberg primitive types (IntegerType -> Integer).","Validate data classes in a unit test before jobs run.","Watch for schema evolution that changes field types without rewriting data."],"tags":["flink","type-mismatch","iceberg-struct"],"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"}