{"record":{"id":"fd6ab2a409ac7a08","repo":"apache/iceberg","slug":"unknown-type-for-long-field-type-name-classnam","errorCode":null,"errorMessage":"Unknown type for long field. Type name: ${className}","messagePattern":"Unknown type for long 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":151,"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":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L133-L169","documentation":"StructRowData.getLong(pos) converts an internal value into a Flink long (epoch-based). It supports Integer, Long, LocalDate, LocalTime, LocalDateTime; anything else raises IllegalStateException 'Unknown type for long field'. This getter backs long/bigint/time/timestamp-millis fields.","triggerScenarios":"A field projected as BIGINT/TIME/TIMESTAMP whose underlying Iceberg value is an unexpected class (e.g. String, TimestampData, OffsetDateTime) - usually from a schema/read-schema mismatch or a custom value reader emitting a different representation.","commonSituations":"Timestamp field conversions where the reader returned OffsetDateTime but StructRowData expects Long/LocalDateTime; partition values or statistics columns with different classes; reading tables written by other Iceberg versions with different time representations.","solutions":["Check the message's class name and align the field's declared Flink type with the actual value class (e.g. use TIMESTAMP(6) not BIGINT for LocalDateTime-backed fields).","Ensure the value reader (FlinkValueReaders/Avro reader) produces supported classes (Integer, Long, LocalDate, LocalTime, LocalDateTime).","Fix the Iceberg schema so the field type matches the data (e.g. Types.LongType for a long field).","Convert the value before it reaches StructRowData, e.g. in a custom projection or reader."],"exampleFix":"// before: reader stores OffsetDateTime, Flink field is BIGINT\nrowType = ROW<ts BIGINT> // getInt->getLong sees OffsetDateTime, throws\n// after: declare the Flink field as TIMESTAMP(6) or convert value to epoch micros Long before projection","handlingStrategy":"type-guard","validationCode":"if (!(v instanceof Integer || v instanceof Long || v instanceof LocalDate || v instanceof LocalTime || v instanceof LocalDateTime)) {\n  throw new IllegalArgumentException(\"value not long-compatible: \" + v.getClass());\n}","typeGuard":"boolean isLongCompatible(Object v) {\n  return v instanceof Integer || v instanceof Long || v instanceof LocalDate\n      || v instanceof LocalTime || v instanceof LocalDateTime;\n}","tryCatchPattern":"try {\n  long l = structRow.getLong(pos);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Unknown type for long field\")) {\n    // convert value to epoch-based Long or fix the declared field type\n  }\n}","preventionTips":["Declare BIGINT only for Long-backed fields; use TIMESTAMP/TIME types otherwise","Avoid zoned types (OffsetDateTime) where StructRowData expects epoch longs","Verify reader output classes with unit tests against the projection"],"tags":["flink","rowdata","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-14T16:17:12.679Z"}