apache/iceberg · error · IllegalArgumentException
Cannot convert to long
Error message
Cannot convert to long: ${value.getClass().getName()} What it means
Conversion failure in RecordConverter.convertLong: the incoming Kafka Connect value for a long-typed field is neither a Number nor a String, so no coercion path applies. The appended class name identifies the value's actual Java type; the topic's schema disagrees with the Iceberg column type.
Solutions
- Emit numeric (or numeric-string) values from the producer for long fields.
- Alter the Iceberg column type to match the real value type.
- Apply a value transformation SMT to normalize types upstream of the sink.
- Route malformed records to a DLQ by catching IllegalArgumentException.
Example fix
// before
record.set("ts", "2024-01-01T00:00:00"); // string date into LongType
// after
record.set("ts", 1704067200000L); // epoch millis Defensive patterns
Strategy: validation
Validate before calling
Object v = record.get("ts");
if (!(v instanceof Number) && !(v instanceof String)) {
throw new IllegalArgumentException("ts must be numeric, got " + v.getClass().getSimpleName());
} Type guard
boolean isLongConvertible(Object v) {
return v instanceof Number || v instanceof String;
} Try / catch
try {
sink.write(record);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("Cannot convert to long")) {
sendToDlq(record, e);
} else throw e;
} Prevention
- Emit timestamps as epoch millis (long) not formatted date strings.
- Enforce producer schemas with the schema registry (int64 fields).
- Test conversion of representative payloads against the table schema before rollout.
When it happens
Trigger: A field mapped to an Iceberg LongType column carrying a Boolean, byte[], Map, List, or other non-numeric non-string value.
Common situations: Producers emitting booleans/objects where the table expects bigint; JSON without schemas where all values become Booleans; nested structs landing in long columns.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot convert to double
- Cannot convert to float
- Cannot convert to int
- Cannot convert date
- Cannot convert time
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/05c808113e133198.
Report an issue: GitHub.
Appendix: source
Thrown at kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java:438
return result;
}
protected int convertInt(Object value) {
if (value instanceof Number) {
return ((Number) value).intValue();
} else if (value instanceof String) {
return Integer.parseInt((String) value);
}
throw new IllegalArgumentException("Cannot convert to int: " + value.getClass().getName());
}
protected long convertLong(Object value) {
if (value instanceof Number) {
return ((Number) value).longValue();
} else if (value instanceof String) {
return Long.parseLong((String) value);
}
throw new IllegalArgumentException("Cannot convert to long: " + value.getClass().getName());
}
protected float convertFloat(Object value) {
if (value instanceof Number) {
return ((Number) value).floatValue();
} else if (value instanceof String) {
return Float.parseFloat((String) value);
}
throw new IllegalArgumentException("Cannot convert to float: " + value.getClass().getName());
}
protected double convertDouble(Object value) {
if (value instanceof Number) {
return ((Number) value).doubleValue();
} else if (value instanceof String) {
return Double.parseDouble((String) value);
}
throw new IllegalArgumentException("Cannot convert to double: " + value.getClass().getName());View on GitHub (pinned to 86d9c8fc54)