apache/flink · error · IllegalArgumentException

Avro does not support LOCAL TIMESTAMP type with precision: %

Error message

Avro does not support LOCAL TIMESTAMP type with precision: %s, it only supports precision less than 6.

What it means

Thrown when converting TIMESTAMP(p) WITHOUT TIME ZONE to an Avro schema with the modern (non-legacy) mapping and precision above 6. Avro logical types only support local-timestamp-millis (p<=3) and local-timestamp-micros (p<=6); nanosecond precision (7-9) has no Avro representation, so the converter refuses it.

Source

Thrown at flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSchemaConverter.java:483

                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 2f3c205e92)

Solutions

  1. Explicitly declare TIMESTAMP(3) or TIMESTAMP(6) for columns written to Avro format.
  2. If nanoseconds must be preserved, store as BIGINT and reinterpret downstream.

Example fix

-- before (TIMESTAMP defaults to precision 9)
event_time TIMESTAMP,

-- after
event_time TIMESTAMP(6),
Defensive patterns

Strategy: validation

Validate before calling

import org.apache.flink.table.types.logical.TimestampType;

boolean avroConvertible(TimestampType t) { return t.getPrecision() <= 6; }

Type guard

boolean fitsAvro(TimestampType t) { return t.getPrecision() <= 6; }

Prevention

When it happens

Trigger: convertToSchema on a TIMESTAMP(7)/TIMESTAMP(8)/TIMESTAMP(9) type; a CREATE TABLE ... WITH ('format'='avro'/'avro-confluent-registry') sink containing a TIMESTAMP(9) column (9 is Flink's default precision for TIMESTAMP).

Common situations: Using plain 'TIMESTAMP' in DDL — Flink defaults it to TIMESTAMP(9), which is too precise for Avro; CDC or IoT pipelines that specify nanosecond event-time columns.

Related errors


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