{"record":{"id":"b2f9f5e645d099ea","repo":"apache/iceberg","slug":"avro-does-not-support-time-type-with-precision-p","errorCode":null,"errorMessage":"Avro does not support TIME type with precision: <precision>, it only supports precision less than 3.","messagePattern":"Avro does not support TIME type with precision: <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":538,"sourceCode":"            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\n                  + \", it only supports precision less than 3.\");\n        }\n        // use int to represents Time, we only support millisecond when deserialization\n        Schema time = LogicalTypes.timeMillis().addToSchema(SchemaBuilder.builder().intType());\n        return nullable ? nullableSchema(time) : time;\n      case DECIMAL:\n        DecimalType decimalType = (DecimalType) logicalType;\n        // store BigDecimal as byte[]\n        Schema decimal =\n            LogicalTypes.decimal(decimalType.getPrecision(), decimalType.getScale())\n                .addToSchema(SchemaBuilder.builder().bytesType());\n        return nullable ? nullableSchema(decimal) : decimal;\n      case ROW:\n        RowType rowType = (RowType) logicalType;\n        List<String> fieldNames = rowType.getFieldNames();\n        // we have to make sure the record name is different in a Schema","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/formats/avro/typeutils/AvroSchemaConverter.java#L520-L556","documentation":"AvroSchemaConverter.convertToSchema maps Flink logical types to Avro schemas. Avro's time logical types (timeMillis/timeMicros) cannot represent Flink TIME with precision greater than 3 (i.e., microsecond) fractional seconds, so the converter rejects it with IllegalArgumentException to avoid silent precision loss.","triggerScenarios":"Calling AvroSchemaConverter.convertToSchema (directly or via fieldBuilder when converting a ROW) with a Flink TimeType whose precision is > 3, e.g. TIME(6).","commonSituations":"Tables or DataStreams defined with TIME(6) or other microsecond-precision TIME columns (Flink default DDL without explicit precision can inherit higher precision), then serialized with the Avro format or written via Avro-based sinks.","solutions":["Change the TIME column precision to TIME(3) or lower before conversion (e.g. CAST(col AS TIME(3)) or alter the table DDL).","If you control the schema source, declare the Flink type as TIMESTAMP(3) instead of higher-precision TIME.","Preprocess the stream with a Map that converts Time to a supported type (e.g. Integer millis or LocalTime truncated to millis) and adjust the schema accordingly."],"exampleFix":"// before: TIME(6) column fails\nSchema s = AvroSchemaConverter.convertToSchema(new TimeType(6));\n\n// after: use millisecond precision\nSchema s = AvroSchemaConverter.convertToSchema(new TimeType(3));","handlingStrategy":"validation","validationCode":"// check TIME precision before conversion\nif (logicalType instanceof TimeType && ((TimeType) logicalType).getPrecision() > 3) {\n    throw new IllegalArgumentException(\"TIME precision must be <= 3 for Avro: \" + logicalType);\n}","typeGuard":"boolean isAvroSafeTime(LogicalType t) {\n    return !(t instanceof TimeType) || ((TimeType) t).getPrecision() <= 3;\n}","tryCatchPattern":null,"preventionTips":["Declare TIME columns with explicit precision TIME(3) or lower","Review table DDL for implicit high-precision time types","Add a schema pre-check step before Avro serialization in pipelines","Prefer TIMESTAMP(3) for microsecond-precision needs with explicit truncation"],"tags":["avro","flink","precision","schema-conversion"],"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"}