{"record":{"id":"df087452dd969cb9","repo":"apache/iceberg","slug":"unknown-type-for-long-field-type-name-longval","errorCode":null,"errorMessage":"Unknown type for long field. Type name: ${longVal.getClass().getName()}","messagePattern":"Unknown type for long field\\. Type name: (.+?)","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"flink/v2.1/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.1/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L134-L170","documentation":"StructRowData.getLong(pos) converts the field at pos to a Flink BIGINT, accepting Long, Date, LocalDate, LocalTime, and LocalDateTime values (converted to epoch units). If the underlying object is any other class, it throws IllegalStateException with the class name. The stored value doesn't match a long-representable Iceberg type.","triggerScenarios":"Calling getLong on a field whose stored value is not Long/Date/LocalDate/LocalTime/LocalDateTime — e.g. a String, BigDecimal, or TimestampData where the schema expected long/timestamp.","commonSituations":"Schema/data mismatch from a custom source or connector feeding wrong object types; wrong accessor chosen for a string or decimal column.","solutions":["Verify the Iceberg schema type for the column is long/date/time/timestamp","Fix the upstream producer so it stores Long or java.time values","Use the matching accessor (getString, getTimestamp, getBigDecimal-equivalent) for the real type"],"exampleFix":"// before\nlong v = structRowData.getLong(pos); // stored value is BigDecimal\n// after\nBigDecimal d = (BigDecimal) structRowData.getValue(pos);\nlong v = d.unscaledValue().longValueExact();","handlingStrategy":"type-guard","validationCode":"Object v = structRowData.getValue(pos);\nif (!(v instanceof Long || v instanceof LocalDate || v instanceof LocalTime || v instanceof LocalDateTime || v instanceof java.util.Date)) {\n  throw new IllegalArgumentException(\"getLong unsupported value at \" + pos + \": \" + (v == null ? \"null\" : v.getClass()));\n}","typeGuard":"boolean longReadable(Object v) { return v instanceof Long || v instanceof LocalDate || v instanceof LocalTime || v instanceof LocalDateTime || v instanceof java.util.Date; }","tryCatchPattern":"try { long x = row.getLong(pos); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"Unknown type for long field\")) { /* use matching accessor */ } else throw e; }","preventionTips":["Use getLong only for long/date/time/timestamp columns","Convert producers to emit Long or java.time types","Assert stored types in connector tests"],"tags":["flink","rowdata","type-mismatch","long"],"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"}