apache/iceberg · error · IllegalArgumentException

Unexpected object type for TIMESTAMP logical type. Received:

Error message

Unexpected object type for TIMESTAMP logical type. Received: " + object

What it means

convertToTimestamp converts the Avro-decoded object for a TIMESTAMP logical type into TimestampData. It accepts java.time.LocalDateTime and (via JodaConverter, if on the classpath) Joda-time objects; any other object type triggers IllegalArgumentException("Unexpected object type for TIMESTAMP logical type. Received: " + object). This happens when the Avro record's actual runtime type doesn't match the declared logical type.

Source

Thrown at flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/formats/avro/AvroToRowDataConverters.java:251

        return TimestampData.fromEpochMillis(timeLong);
      } else if (precision <= 6) {
        return TimestampData.fromEpochMillis(
            Math.floorDiv(timeLong, 1000L), (int) Math.floorMod(timeLong, 1000L) * 1000);
      } else {
        // Iceberg: Added support for nanoseconds precision (FLINK-39251)
        return TimestampData.fromEpochMillis(
            Math.floorDiv(timeLong, 1_000_000L), (int) Math.floorMod(timeLong, 1_000_000L));
      }
    } else if (object instanceof Instant) {
      return TimestampData.fromInstant((Instant) object);
    } else if (object instanceof LocalDateTime) {
      return TimestampData.fromLocalDateTime((LocalDateTime) object);
    } else {
      JodaConverter jodaConverter = JodaConverter.getConverter();
      if (jodaConverter != null) {
        return TimestampData.fromEpochMillis(jodaConverter.convertTimestamp(object));
      } else {
        throw new IllegalArgumentException(
            "Unexpected object type for TIMESTAMP logical type. Received: " + object);
      }
    }
  }

  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 86d9c8fc54)

Solutions

  1. Align the Avro field's logical type with the Flink type: use TIMESTAMP_WITH_LOCAL_TIME_ZONE for Instant-backed fields.
  2. Ensure joda-time is on the classpath if consuming legacy Avro data.
  3. Inspect the received object printed in the message and add/fix the converter path for that type.

Example fix

// before
DataTypes.TIMESTAMP(3) // for Avro timestamp-millis (Instant)
// after
DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)
Defensive patterns

Strategy: type-guard

Validate before calling

// ensure joda-time is present when legacy Avro data is expected
Class.forName("org.joda.time.DateTime");

Type guard

boolean isSupportedTimestampObject(Object o) { return o instanceof LocalDateTime || (o instanceof org.joda.time.DateTime && JodaConverter.getConverter() != null); }

Try / catch

try { TimestampData ts = convertToTimestamp(avroObject, type); } catch (IllegalArgumentException e) { /* inspect e.getMessage() for the actual runtime type */ }

Prevention

When it happens

Trigger: An Avro field declared as timestamp logical type decodes to neither LocalDateTime nor a Joda-supported type — e.g. a java.time.Instant arriving in a converter path expecting LocalDateTime, or the Joda converter returning null because Joda classes are absent.

Common situations: Mixing timestamp-millis/micros (Instant-backed) Avro fields with a WITHOUT_TIME_ZONE RowData converter; missing Joda-time dependency in the runtime so JodaConverter.getConverter() returns null; producer writing a different Avro schema than declared.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/af36e317e1855e29. Report an issue: GitHub.