{"record":{"id":"387e9df3ec25a8d3","repo":"apache/iceberg","slug":"avro-does-not-support-timestamp-type-with-precisio-387e9d","errorCode":null,"errorMessage":"Avro does not support TIMESTAMP type with precision: <precision>, it only supports precision less than 6.","messagePattern":"Avro does not support TIMESTAMP type with precision: <precision>, it only supports precision less than 6\\.","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":522,"sourceCode":"                    + \", it only supports precision less than 6.\");\n          }\n        }\n        Schema timestamp = avroLogicalType.addToSchema(SchemaBuilder.builder().longType());\n        return nullable ? nullableSchema(timestamp) : timestamp;\n      case TIMESTAMP_WITH_LOCAL_TIME_ZONE:\n        if (legacyTimestampMapping) {\n          throw new UnsupportedOperationException(\n              \"Unsupported to derive Schema for type: \" + logicalType);\n        } else {\n          final LocalZonedTimestampType localZonedTimestampType =\n              (LocalZonedTimestampType) logicalType;\n          precision = localZonedTimestampType.getPrecision();\n          if (precision <= 3) {\n            avroLogicalType = LogicalTypes.timestampMillis();\n          } else if (precision <= 6) {\n            avroLogicalType = LogicalTypes.timestampMicros();\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 6.\");\n          }\n          timestamp = avroLogicalType.addToSchema(SchemaBuilder.builder().longType());\n          return nullable ? nullableSchema(timestamp) : timestamp;\n        }\n      case DATE:\n        // use int to represents Date\n        Schema date = LogicalTypes.date().addToSchema(SchemaBuilder.builder().intType());\n        return nullable ? nullableSchema(date) : date;\n      case TIME_WITHOUT_TIME_ZONE:\n        precision = ((TimeType) logicalType).getPrecision();\n        if (precision > 3) {\n          throw new IllegalArgumentException(\n              \"Avro does not support TIME type with precision: \"\n                  + precision","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/formats/avro/typeutils/AvroSchemaConverter.java#L504-L540","documentation":"When converting TIMESTAMP_WITH_LOCAL_TIME_ZONE to Avro with legacyTimestampMapping=false, precision <= 3 maps to timestampMillis and <= 6 to timestampMicros; precision above 6 (7-9) exceeds what Avro instant logical types support, so IllegalArgumentException \"...it only supports precision less than 6\" is thrown.","triggerScenarios":"AvroSchemaConverter.convertToSchema(LogicalType, boolean) — directly or via nested fieldBuilder — with a LocalZonedTimestampType whose precision is 7-9, e.g. TIMESTAMP_LTZ(9).","commonSituations":"Nanosecond-precision TIMESTAMP_LTZ columns from sources like Kafka connect or CDC; Flink type inference producing TIMESTAMP_LTZ(9) by default for certain expressions; DDL copying source precision without reduction.","solutions":["Declare the column as TIMESTAMP_LTZ(6) or lower in the Flink DDL.","Cast before conversion: CAST(ts AS TIMESTAMP_LTZ(6)).","If nanosecond precision is essential, store as BIGINT epoch nanos since Avro instant logical types cap at micros.","Confirm the value truly needs >micros precision; most systems silently truncate anyway."],"exampleFix":"// before\nSchema s = AvroSchemaConverter.convertToSchema(new LocalZonedTimestampType(9), false); // throws\n// after\nSchema s = AvroSchemaConverter.convertToSchema(new LocalZonedTimestampType(6), false); // timestampMicros","handlingStrategy":"validation","validationCode":"LocalZonedTimestampType ts = (LocalZonedTimestampType) logicalType;\nif (!legacyMapping && ts.getPrecision() > 6) {\n  throw new IllegalStateException(\"TIMESTAMP_LTZ(\" + ts.getPrecision() + \") exceeds Avro micros limit; use <= 6\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Schema s = AvroSchemaConverter.convertToSchema(ltzType, false);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"TIMESTAMP type\") && e.getMessage().contains(\"less than 6\")) {\n    s = AvroSchemaConverter.convertToSchema(new LocalZonedTimestampType(6), false);\n  } else throw e;\n}","preventionTips":["Cap TIMESTAMP_LTZ precision at 6 in DDL; Avro instants max at micros.","CAST TIMESTAMP_LTZ(7-9) down in the pipeline before schema conversion.","Store sub-microsecond values as separate BIGINT fields if needed."],"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"}