apache/flink · error · IllegalArgumentException
Unexpected object type for TIMESTAMP logical type. Received:
Error message
Unexpected object type for TIMESTAMP logical type. Received: {} What it means
convertToTimestamp accepts only Long (epoch millis), java.time.Instant, java.time.LocalDateTime, or Joda types (when JodaConverter is on the classpath). Any other Java object appearing where an Avro timestamp logical type is expected throws IllegalArgumentException with the received type's toString().
Source
Thrown at flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroToRowDataConverters.java:227
}
return new GenericMapData(result);
};
}
private static TimestampData convertToTimestamp(Object object) {
final long millis;
if (object instanceof Long) {
millis = (Long) object;
} else if (object instanceof Instant) {
millis = ((Instant) object).toEpochMilli();
} else if (object instanceof LocalDateTime) {
return TimestampData.fromLocalDateTime((LocalDateTime) object);
} else {
JodaConverter jodaConverter = JodaConverter.getConverter();
if (jodaConverter != null) {
millis = jodaConverter.convertTimestamp(object);
} else {
throw new IllegalArgumentException(
"Unexpected object type for TIMESTAMP logical type. Received: " + object);
}
}
return TimestampData.fromEpochMillis(millis);
}
private static int convertToDate(Object object) {
if (object instanceof Integer) {
return (Integer) object;
} else if (object instanceof LocalDate) {
return (int) ((LocalDate) object).toEpochDay();
} else {
JodaConverter jodaConverter = JodaConverter.getConverter();
if (jodaConverter != null) {
return (int) jodaConverter.convertDate(object);
} else {
throw new IllegalArgumentException(
"Unexpected object type for DATE logical type. Received: " + object);View on GitHub (pinned to 2f3c205e92)
Solutions
- Compare writer and reader schemas for the timestamp field and align them so Avro decodes to Long/Instant.
- If the source genuinely stores strings, read it as STRING and convert with a UDF/mapper instead of declaring it TIMESTAMP in the Avro mapping.
- Verify Joda support if the data contains org.joda.time values: keep joda-time on the classpath so JodaConverter.getConverter() returns non-null.
Example fix
// before
// reader schema: {"name":"ts","type":{"type":"long","logicalType":"timestamp-millis"}}
// writer schema: {"name":"ts","type":"string"} -> crashes
// after
// declare the field STRING in the table schema and convert:
SELECT TO_TIMESTAMP_LTZ(CAST(ts AS BIGINT), 3) ... -- if producer writes epoch millis as text Defensive patterns
Strategy: type-guard
Validate before calling
Object v = record.get(fieldPos);
boolean ok = v instanceof Long || v instanceof Instant || v instanceof LocalDateTime;
if (!ok && JodaConverter.getConverter() == null) {
throw new IllegalArgumentException("Unconvertible timestamp value: " + (v == null ? "null" : v.getClass()));
} Type guard
static boolean isAvroTimestampValue(Object v) {
return v instanceof Long || v instanceof Instant || v instanceof LocalDateTime
|| (JodaConverter.getConverter() != null && JodaConverter.getConverter().convertsTimestamp(v));
} Prevention
- Verify the writer schema marks timestamp fields with the timestamp-millis/micros logicalType.
- Sample and type-check incoming records before full ingestion.
- Keep joda-time on the classpath if producers emit Joda values.
When it happens
Trigger: The Avro data value for a timestamp field is a String, GenericFixed, Integer, or a custom class; e.g. a producer wrote timestamps as strings, or the writer schema declared no logical type so Avro decoded the field as something other than the expected Long/Instant.
Common situations: Writer/reader schema mismatch: field declared as timestamp-millis in the reader but plain long/string/fixed in the writer; heterogeneous producers; third-party Avro data with non-standard timestamp encodings.
Related errors
- Unexpected object type for DATE logical type. Received: {}
- Unexpected object type for TIME logical type. Received: {}
- Failed to serialize schema registry.
- Unsupported type: {}
- Avro does not support TIMESTAMP type with precision: %s, it
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/a3ee852823c6fcf1.
Report an issue: GitHub.