{"record":{"id":"4026c28ab3e13b0a","repo":"apache/iceberg","slug":"unknown-type-for-long-field-type-name","errorCode":null,"errorMessage":"Unknown type for long field. Type name: ","messagePattern":"Unknown type for long 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":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.3/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L134-L170","documentation":"StructRowData.getLong converts a struct field into a Flink long, accepting Long, LocalTime (nanos of day), LocalDateTime, OffsetDateTime and Instant (as microseconds). Any other class triggers this IllegalStateException. It means the stored value's Java class does not correspond to the Iceberg long/time/timestamp field it occupies.","triggerScenarios":"Calling getLong(pos) where the field object is, e.g., an Integer, String or BigDecimal instead of Long or a supported time type.","commonSituations":"Writers producing Integer for LongType fields; timestamps stored as String or Timestamp objects rather than the expected java.time classes; mismatched Flink LogicalType vs Iceberg type when bridging.","solutions":["Inspect the class name in the message and ensure long/timestamp fields are written as Long or the supported java.time types.","Confirm the Iceberg field is LongType/TimestampType as declared in the schema.","Convert the value to the expected type in the producing pipeline before writing."],"exampleFix":"// before\nrow.setField(pos, someTimestamp); // java.sql.Timestamp not supported here\n\n// after\nrow.setField(pos, someTimestamp.toLocalDateTime());","handlingStrategy":"type-guard","validationCode":"Object v = struct.getField(pos);\nif (!(v instanceof Long || v instanceof LocalTime || v instanceof LocalDateTime || v instanceof OffsetDateTime || v instanceof Instant)) {\n  throw new IllegalArgumentException(\"Unexpected class for long field: \" + v.getClass());\n}","typeGuard":"boolean isLongCompatible(Object v) {\n  return v instanceof Long || v instanceof LocalTime || v instanceof LocalDateTime\n      || v instanceof OffsetDateTime || v instanceof Instant;\n}","tryCatchPattern":"try {\n  long value = rowData.getLong(pos);\n} catch (IllegalStateException e) {\n  // inspect the class name in the message and convert upstream\n}","preventionTips":["Store LongType fields as java.lang.Long, never Integer or String.","Use java.time types (LocalDateTime/OffsetDateTime) for timestamp fields.","Add pre-read assertions in converters between Iceberg schema and Java objects."],"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"}