{"record":{"id":"8fd43885c8f45ec8","repo":"apache/beam","slug":"timestamp-logical-type-precision-not-supported-precision","errorCode":null,"errorMessage":"Timestamp logical type precision not supported:${precision}","messagePattern":"Timestamp logical type precision not supported:(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtils.java","lineNumber":1229,"sourceCode":"                  oneOfType.getOneOfSchema().getFields().stream()\n                      .map(x -> getFieldSchema(x.getType(), x.getName(), namespace))\n                      .collect(Collectors.toList()));\n        } else if (\"DATE\".equals(identifier) || SqlTypes.DATE.getIdentifier().equals(identifier)) {\n          baseType =\n              LogicalTypes.date()\n                  .addToSchema(org.apache.avro.Schema.create(org.apache.avro.Schema.Type.INT));\n        } else if (\"TIME\".equals(identifier)) {\n          baseType =\n              LogicalTypes.timeMillis()\n                  .addToSchema(org.apache.avro.Schema.create(org.apache.avro.Schema.Type.INT));\n        } else if (SqlTypes.TIMESTAMP.getIdentifier().equals(identifier)) {\n          baseType =\n              LogicalTypes.timestampMicros()\n                  .addToSchema(org.apache.avro.Schema.create(org.apache.avro.Schema.Type.LONG));\n        } else if (Timestamp.IDENTIFIER.equals(identifier)) {\n          int precision = checkNotNull(logicalType.getArgument());\n          if (precision != 9) {\n            throw new RuntimeException(\n                \"Timestamp logical type precision not supported:\" + precision);\n          }\n          baseType = org.apache.avro.Schema.create(org.apache.avro.Schema.Type.LONG);\n          baseType.addProp(\"logicalType\", TIMESTAMP_NANOS_LOGICAL_TYPE);\n        } else {\n          throw new RuntimeException(\n              \"Unhandled logical type \" + checkNotNull(fieldType.getLogicalType()).getIdentifier());\n        }\n        break;\n\n      case ARRAY:\n      case ITERABLE:\n        baseType =\n            org.apache.avro.Schema.createArray(\n                getFieldSchema(\n                    checkNotNull(fieldType.getCollectionElementType()), fieldName, namespace));\n        break;\n","sourceCodeStart":1211,"sourceCodeEnd":1247,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtils.java#L1211-L1247","documentation":"When converting a Beam FieldType with a Timestamp logical type to an Avro schema, only nanosecond precision (precision == 9) is accepted. Any other precision value throws RuntimeException because the library cannot faithfully express that precision in Avro's logical-type model.","triggerScenarios":"Calling AvroUtils.getFieldSchema/toAvroSchema on a FieldType whose logical type identifier is Timestamp and whose precision argument is not 9 (e.g. microsecond precision 6 or millisecond precision 3).","commonSituations":"Pipeline schemas built with TIMESTAMP logical types read from sources with different precision (e.g. JDBC microseconds), or SDK-version changes where the default timestamp precision differs; writing Beam rows to Avro/Parquet files.","solutions":["Use TIMESTAMP_NANOSECONDS (precision 9) for the field so conversion succeeds.","Explicitly set the timestamp precision to 9 when constructing the FieldType logical type.","Convert the value to nanoseconds (scale the instant) before writing, or store as LONG without the logical type.","Catch RuntimeException and emit the field with a supported precision or drop it with a warning."],"exampleFix":"// before\nFieldType.of(TypeName.DATETIME).withLogicalType(LogicalTypes.timestamp(6))\n// after\nFieldType.of(TypeName.DATETIME).withLogicalType(LogicalTypes.timestamp(9))","handlingStrategy":"validation","validationCode":"boolean isSupportedTimestamp(FieldType ft) {\n  LogicalType lt = ft.getLogicalType();\n  return lt == null\n      || !Timestamp.IDENTIFIER.equals(lt.getIdentifier())\n      || (Integer) 9 == checkNotNull(lt.getArgument());\n}","typeGuard":null,"tryCatchPattern":"try {\n  org.apache.avro.Schema s = AvroUtils.toAvroSchema(beamSchema);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Timestamp logical type precision not supported:\")) {\n    // re-map the field to precision 9 and retry\n  } else { throw e; }\n}","preventionTips":["Standardize on nanosecond (precision 9) timestamps across pipeline schemas.","Check logical-type precision at schema registration time, not at sink write time.","Scale timestamps to the required precision before writing to Avro.","Pin Beam versions across pipeline stages so default precisions agree."],"tags":["avro","beam","logical-type","timestamp","precision"],"backgroundTag":"unsupported-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}