apache/flink · error · IllegalArgumentException

Unexpected object type for DATE logical type. Received: {}

Error message

Unexpected object type for DATE logical type. Received: {}

What it means

convertToDate accepts only Integer (days since epoch) or java.time.LocalDate (plus Joda types when joda-time is present). Any other object decoded for a DATE logical-type field throws IllegalArgumentException naming the received value.

Source

Thrown at flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroToRowDataConverters.java:244

            } 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);
            }
        }
    }

    private static int convertToTime(Object object) {
        final int millis;
        if (object instanceof Integer) {
            millis = (Integer) object;
        } else if (object instanceof LocalTime) {
            millis = ((LocalTime) object).get(ChronoField.MILLI_OF_DAY);
        } else {
            JodaConverter jodaConverter = JodaConverter.getConverter();
            if (jodaConverter != null) {
                millis = jodaConverter.convertTime(object);
            } else {
                throw new IllegalArgumentException(
                        "Unexpected object type for TIME logical type. Received: " + object);

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Ensure the writer schema declares {"type":"int","logicalType":"date"} and data was encoded as int days-since-epoch.
  2. If data is textual, map the column as STRING/DATE via CAST in SQL instead of relying on the Avro logical type.
  3. Convert string dates to epoch-days before writing them as Avro.

Example fix

// before
// writer: {"name":"d","type":"string"} + reader expects DATE -> crash

// after
// writer: {"name":"d","type":{"type":"int","logicalType":"date"}}
// or in SQL: CAST(d AS DATE) from a STRING column
Defensive patterns

Strategy: type-guard

Validate before calling

Object v = record.get(fieldPos);
if (!(v instanceof Integer) && !(v instanceof LocalDate)
        && JodaConverter.getConverter() == null) {
    throw new IllegalArgumentException("Unconvertible date value class: " + v.getClass());
}

Type guard

static boolean isAvroDateValue(Object v) {
    return v instanceof Integer || v instanceof LocalDate;
}

Prevention

When it happens

Trigger: The Avro value for a date field is a String ('2024-01-01'), Long, or other type — typically because the writer schema lacks the 'date' logicalType (so Avro yields a plain value) or stores dates as strings.

Common situations: Producer wrote date fields as ISO strings; schema evolution stripped logical type annotations; avro-tools generated schemas without logicalTypes for legacy data.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/5da48ebf3a81a172. Report an issue: GitHub.