{"record":{"id":"792c42172d60aaa5","repo":"apache/beam","slug":"datetime64-precision-must-be-in-0-9-got","errorCode":null,"errorMessage":"DateTime64 precision must be in [0, 9], got ","messagePattern":"DateTime64 precision must be in \\[0, 9\\], got ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/TableSchema.java","lineNumber":317,"sourceCode":"    public static ColumnType fixedString(int size) {\n      return ColumnType.builder()\n          .typeName(TypeName.FIXEDSTRING)\n          .nullable(false)\n          .fixedStringSize(size)\n          .build();\n    }\n\n    /** Default {@code DateTime64} precision in ClickHouse. */\n    public static final int DEFAULT_DATETIME64_PRECISION = 3;\n\n    /** Returns a {@code DateTime64} type with ClickHouse's default precision of 3. */\n    public static ColumnType dateTime64() {\n      return dateTime64(DEFAULT_DATETIME64_PRECISION);\n    }\n\n    public static ColumnType dateTime64(int precision) {\n      if (precision < 0 || precision > 9) {\n        throw new IllegalArgumentException(\n            \"DateTime64 precision must be in [0, 9], got \" + precision);\n      }\n      return ColumnType.builder()\n          .typeName(TypeName.DATETIME64)\n          .nullable(false)\n          .precision(precision)\n          .build();\n    }\n\n    /** Default {@code Decimal} precision in ClickHouse when none is specified. */\n    public static final int DEFAULT_DECIMAL_PRECISION = 10;\n\n    /** Default {@code Decimal} scale in ClickHouse when none is specified. */\n    public static final int DEFAULT_DECIMAL_SCALE = 0;\n\n    /**\n     * Returns a {@code Decimal(precision, scale)} type.\n     *","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/TableSchema.java#L299-L335","documentation":"Thrown by TableSchema.ColumnType.dateTime64(int) when the requested DateTime64 precision is outside the ClickHouse-valid range [0, 9]. Precision sets the number of sub-second digits (0=seconds, 3=millis, 9=nanos); other values cannot map to a valid ClickHouse type.","triggerScenarios":"Calling ColumnType.dateTime64(precision) with a negative value, a value > 9, or precision taken unvalidated from a parsed schema string (e.g. DateTime64(12)).","commonSituations":"Parsing ClickHouse DDL where precision came from an unchecked regex group; copying DateTime64(12) definitions from other systems; defaulting an unset precision field to a sentinel like -1.","solutions":["Validate or clamp precision to [0, 9] before calling dateTime64(precision).","Choose 9 (nanoseconds) if the source has finer resolution, truncating the source data.","Fix the schema-string parser to accept only valid precision values.","Ensure unset precision falls back to dateTime64() (default) rather than a sentinel."],"exampleFix":"// before\nColumnType t = TableSchema.ColumnType.dateTime64(12); // out of range\n// after\nint p = Math.min(9, Math.max(0, parsedPrecision));\nColumnType t = TableSchema.ColumnType.dateTime64(p);","handlingStrategy":"validation","validationCode":"int validDateTime64Precision(int precision) {\n  if (precision < 0 || precision > 9) {\n    throw new IllegalArgumentException(\"DateTime64 precision must be in [0, 9]: \" + precision);\n  }\n  return precision;\n}\n// call: TableSchema.ColumnType.dateTime64(validDateTime64Precision(p))","typeGuard":null,"tryCatchPattern":"try {\n  ColumnType t = TableSchema.ColumnType.dateTime64(parsedPrecision);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"precision must be in [0, 9]\")) {\n    LOG.warn(\"Invalid DateTime64 precision {}, falling back to default\", parsedPrecision);\n    return TableSchema.ColumnType.dateTime64();\n  }\n  throw e;\n}","preventionTips":["Restrict DDL parsers to accept only DateTime64 precision 0..9.","Use 3 for millis and 9 for nanos; ClickHouse supports nothing beyond 9.","Clamp rather than pass through user-supplied precision values.","Test schema construction with boundary values 0 and 9."],"tags":["clickhouse","schema","datetime64","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}