apache/iceberg · error · IllegalArgumentException

Avro does not support LOCAL TIMESTAMP type with precision: $

Error message

Avro does not support LOCAL TIMESTAMP type with precision: ${precision}, it only supports precision less than 6.

What it means

When converting a Flink TIMESTAMP (TIMESTAMP_WITHOUT_TIME_ZONE) to Avro with legacyTimestampMapping=false, precision <= 3 maps to localTimestampMillis and <= 6 to localTimestampMicros; anything higher (7-9) has no Avro local-timestamp logical type, so IllegalArgumentException "...it only supports precision less than 6" is thrown.

Source

Thrown at flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/formats/avro/typeutils/AvroSchemaConverter.java:500

        precision = timestampType.getPrecision();
        org.apache.avro.LogicalType avroLogicalType;
        if (legacyTimestampMapping) {
          if (precision <= 3) {
            avroLogicalType = LogicalTypes.timestampMillis();
          } else {
            throw new IllegalArgumentException(
                "Avro does not support TIMESTAMP type "
                    + "with precision: "
                    + precision
                    + ", it only supports precision less than 3.");
          }
        } else {
          if (precision <= 3) {
            avroLogicalType = LogicalTypes.localTimestampMillis();
          } else if (precision <= 6) {
            avroLogicalType = LogicalTypes.localTimestampMicros();
          } else {
            throw new IllegalArgumentException(
                "Avro does not support LOCAL TIMESTAMP type "
                    + "with precision: "
                    + precision
                    + ", it only supports precision less than 6.");
          }
        }
        Schema timestamp = avroLogicalType.addToSchema(SchemaBuilder.builder().longType());
        return nullable ? nullableSchema(timestamp) : timestamp;
      case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
        if (legacyTimestampMapping) {
          throw new UnsupportedOperationException(
              "Unsupported to derive Schema for type: " + logicalType);
        } else {
          final LocalZonedTimestampType localZonedTimestampType =
              (LocalZonedTimestampType) logicalType;
          precision = localZonedTimestampType.getPrecision();
          if (precision <= 3) {
            avroLogicalType = LogicalTypes.timestampMillis();

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Reduce the column precision to TIMESTAMP(6) or lower in the Flink DDL/schema.
  2. Cast in the pipeline: CAST(ts AS TIMESTAMP(6)) before conversion.
  3. If nanosecond fidelity is required, store as a different type (e.g. BIGINT epoch nanos) since Avro logical types max at micros.
  4. Note: unlike the legacy path, non-legacy mapping supports up to precision 6 — check which mapping mode is active.

Example fix

// before
CREATE TABLE t (ts TIMESTAMP(9)) ...; // conversion throws
// after
CREATE TABLE t (ts TIMESTAMP(6)) ...; // maps to localTimestampMicros
Defensive patterns

Strategy: validation

Validate before calling

TimestampType ts = (TimestampType) logicalType;
if (!legacyMapping && ts.getPrecision() > 6) {
  throw new IllegalStateException("TIMESTAMP(" + ts.getPrecision() + ") exceeds Avro micros limit; use <= 6");
}

Try / catch

try {
  Schema s = AvroSchemaConverter.convertToSchema(timestampType, false);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("LOCAL TIMESTAMP") && e.getMessage().contains("less than 6")) {
    s = AvroSchemaConverter.convertToSchema(new TimestampType(6), false);
  } else throw e;
}

Prevention

When it happens

Trigger: AvroSchemaConverter.convertToSchema(LogicalType, boolean) — directly or via nested fieldBuilder — with TimestampType precision > 6 and legacyTimestampMapping=false, e.g. TIMESTAMP(9).

Common situations: Flink defaults TIMESTAMP to precision 6 in some paths; nanosecond-precision columns (TIMESTAMP(9)) declared in DDL; automatic inference assigning high precision from source connectors.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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