{"record":{"id":"4c2cf2efa008f68a","repo":"apache/iceberg","slug":"unknown-type-for-long-field-type-name-longva","errorCode":null,"errorMessage":"Unknown type for long field. Type name: \" + longVal.getClass().getName()","messagePattern":"Unknown type for long field\\. Type name: \" \\+ longVal\\.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":152,"sourceCode":"\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))\n              .toNanos()\n          / 1000;\n    } else {\n      throw new IllegalStateException(\n          \"Unknown type for long field. Type name: \" + longVal.getClass().getName());\n    }\n  }\n\n  @Override\n  public float getFloat(int pos) {\n    return struct.get(pos, Float.class);\n  }\n\n  @Override\n  public double getDouble(int pos) {\n    return struct.get(pos, Double.class);\n  }\n\n  @Override\n  public StringData getString(int pos) {\n    return isNullAt(pos) ? null : getStringDataInternal(pos);\n  }","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L134-L170","documentation":"StructRowData.getLong converts the Object in the wrapped StructLike at pos into a Flink BIGINT. It accepts Long plus Iceberg's time-oriented java.time representations: OffsetDateTime (timestamptz), LocalDate (date), LocalTime (time), and LocalDateTime (timestamp). Any other stored type triggers IllegalStateException naming the class, meaning the field's runtime type doesn't match a long-typed Iceberg column.","triggerScenarios":"Reading a long/bigint, timestamp, date or time column via StructRowData.getLong(pos) when the StructLike stores an unexpected object type (e.g. Integer, BigDecimal, String, java.util.Date) instead of Long or one of the supported java.time types.","commonSituations":"Custom readers/writers that populate StructLike rows with java.util.Date or String timestamps; schema mismatch between reader schema and physical data; third-party StructLike adapters (Hive/Spark records) mapping timestamp columns to types Iceberg's Flink reader doesn't expect.","solutions":["Inspect the class name in the message and convert that stored type to Long (or OffsetDateTime/LocalDate/LocalTime/LocalDateTime) at the source.","Ensure the read schema matches the files' written schema so long columns are decoded as the expected representations.","If using a custom StructLike/wrapper, normalize timestamp/date values to java.time types before wrapping in StructRowData.","Pre-convert values yourself: read via struct.get(pos, Object.class), map to long, and avoid relying on StructRowData's limited instanceof chain."],"exampleFix":"// before\nlong v = structRowData.getLong(pos); // fails when stored as java.util.Date\n\n// after\nObject raw = struct.get(pos, Object.class);\nlong v = (raw instanceof java.util.Date d)\n    ? d.toInstant().toEpochMilli() * 1000L\n    : structRowData.getLong(pos);","handlingStrategy":"validation","validationCode":"Object raw = struct.get(pos, Object.class);\nPreconditions.checkArgument(\n    raw == null || raw instanceof Long || raw instanceof OffsetDateTime\n        || raw instanceof LocalDate || raw instanceof LocalTime || raw instanceof LocalDateTime,\n    \"long field holds unexpected type: %s\", raw == null ? \"null\" : raw.getClass());","typeGuard":"boolean isLongRepresentable(Object v) {\n  return v instanceof Long || v instanceof OffsetDateTime || v instanceof LocalDate\n      || v instanceof LocalTime || v instanceof LocalDateTime;\n}","tryCatchPattern":"try {\n  long v = structRowData.getLong(pos);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Unknown type for long field\")) {\n    log.error(\"Long column at pos {} stores incompatible type\", pos, e);\n    throw new SchemaMismatchException(e);\n  }\n  throw e;\n}","preventionTips":["Normalize all timestamp/date/time values to java.time types when populating StructLike rows.","Never store java.util.Date, String, or BigDecimal in long/timestamp columns."],"tags":["flink","structlike","type-mismatch","timestamp"],"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"}