{"record":{"id":"48b7f16fce185651","repo":"apache/iceberg","slug":"avro-does-not-support-timestamp-type-with-precisio","errorCode":null,"errorMessage":"Avro does not support TIMESTAMP type with precision: ${precision}, it only supports precision less than 3.","messagePattern":"Avro does not support TIMESTAMP type with precision: (.+?), it only supports precision less than 3\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/formats/avro/typeutils/AvroSchemaConverter.java","lineNumber":488,"sourceCode":"        return nullable ? nullableSchema(doubleSchema) : doubleSchema;\n      case CHAR:\n      case VARCHAR:\n        Schema str = SchemaBuilder.builder().stringType();\n        return nullable ? nullableSchema(str) : str;\n      case BINARY:\n      case VARBINARY:\n        Schema binary = SchemaBuilder.builder().bytesType();\n        return nullable ? nullableSchema(binary) : binary;\n      case TIMESTAMP_WITHOUT_TIME_ZONE:\n        // use long to represents Timestamp\n        final TimestampType timestampType = (TimestampType) logicalType;\n        precision = timestampType.getPrecision();\n        org.apache.avro.LogicalType avroLogicalType;\n        if (legacyTimestampMapping) {\n          if (precision <= 3) {\n            avroLogicalType = LogicalTypes.timestampMillis();\n          } else {\n            throw new IllegalArgumentException(\n                \"Avro does not support TIMESTAMP type \"\n                    + \"with precision: \"\n                    + precision\n                    + \", it only supports precision less than 3.\");\n          }\n        } else {\n          if (precision <= 3) {\n            avroLogicalType = LogicalTypes.localTimestampMillis();\n          } else if (precision <= 6) {\n            avroLogicalType = LogicalTypes.localTimestampMicros();\n          } else {\n            throw new IllegalArgumentException(\n                \"Avro does not support LOCAL TIMESTAMP type \"\n                    + \"with precision: \"\n                    + precision\n                    + \", it only supports precision less than 6.\");\n          }\n        }","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/formats/avro/typeutils/AvroSchemaConverter.java#L470-L506","documentation":"When converting a Flink TIMESTAMP (TIMESTAMP_WITHOUT_TIME_ZONE) LogicalType to an Avro schema with legacyTimestampMapping=true, only precision <= 3 is representable (timestampMillis). Higher precision has no legacy Avro logical type, so IllegalArgumentException stating Avro supports only precision less than 3 is thrown.","triggerScenarios":"AvroSchemaConverter.convertToSchema(LogicalType, boolean) — also reached recursively via fieldBuilder for nested fields — with a TimestampType whose precision > 3 while legacyTimestampMapping is true (e.g. TIMESTAMP(6), the Flink default).","commonSituations":"Flink SQL DDL declaring TIMESTAMP(6)/(9) but the Avro writer configured with legacy timestamp mapping; older Flink/Iceberg configs setting legacy mapping for backward compatibility with pre-1.10 consumers.","solutions":["Pass legacyTimestampMapping=false to convertToSchema so precision <= 6 maps to localTimestampMicros/timestampMicros variants.","Change the column to TIMESTAMP(3) or lower in the Flink DDL so it fits timestampMillis.","Cast the column in SQL: CAST(ts AS TIMESTAMP(3)) before writing to Avro.","Migrate downstream consumers to non-legacy (logical-type) Avro timestamps, then disable legacy mapping."],"exampleFix":"// before\nSchema s = AvroSchemaConverter.convertToSchema(new TimestampType(6), true); // throws\n// after\nSchema s = AvroSchemaConverter.convertToSchema(new TimestampType(6), false); // micros logical type\n// or lower the precision: new TimestampType(3)","handlingStrategy":"validation","validationCode":"TimestampType ts = (TimestampType) logicalType;\nif (legacyMapping && ts.getPrecision() > 3) {\n  throw new IllegalStateException(\"TIMESTAMP(\" + ts.getPrecision() + \") needs legacyTimestampMapping=false or precision <= 3\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Schema s = AvroSchemaConverter.convertToSchema(timestampType, legacyMapping);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"it only supports precision less than 3\")) {\n    s = AvroSchemaConverter.convertToSchema(new TimestampType(3), legacyMapping); // degrade precision\n  } else throw e;\n}","preventionTips":["Declare timestamp columns as TIMESTAMP(3) when legacy Avro consumers are involved.","Avoid enabling legacyTimestampMapping for new pipelines.","CAST high-precision timestamps down before writing to Avro."],"tags":["avro","flink","timestamp","precision"],"backgroundTag":"value-out-of-range","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}