{"record":{"id":"faf0b8fccb0d12d3","repo":"apache/beam","slug":"decimal-precision-must-be-in-1-76-got","errorCode":null,"errorMessage":"Decimal precision must be in [1, 76], got ","messagePattern":"Decimal precision must be in \\[1, 76\\], 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":346,"sourceCode":"    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     *\n     * <p>ClickHouse stores {@code Decimal} values as integers of a width chosen from the declared\n     * precision: 32 bits for precision 1–9, 64 for 10–18, 128 for 19–38 and 256 for 39–76. The\n     * width aliases {@code Decimal32(S)}, {@code Decimal64(S)}, {@code Decimal128(S)} and {@code\n     * Decimal256(S)} correspond to precisions 9, 18, 38 and 76.\n     *\n     * @param precision total number of decimal digits, in {@code [1, 76]}\n     * @param scale number of fractional decimal digits, in {@code [0, precision]}\n     */\n    public static ColumnType decimal(int precision, int scale) {\n      if (precision < 1 || precision > 76) {\n        throw new IllegalArgumentException(\n            \"Decimal precision must be in [1, 76], got \" + precision);\n      }\n      if (scale < 0 || scale > precision) {\n        throw new IllegalArgumentException(\n            \"Decimal scale must be in [0, \" + precision + \"], got \" + scale);\n      }\n      return ColumnType.builder()\n          .typeName(TypeName.DECIMAL)\n          .nullable(false)\n          .precision(precision)\n          .scale(scale)\n          .build();\n    }\n\n    public static ColumnType enum8(Map<String, Integer> enumValues) {\n      return ColumnType.builder()\n          .typeName(TypeName.ENUM8)\n          .nullable(false)","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/TableSchema.java#L328-L364","documentation":"Thrown by TableSchema.ColumnType.decimal(int, int) when the requested Decimal precision is outside the ClickHouse-supported range [1, 76]. ClickHouse Decimals allow 1-76 total digits; a companion check further restricts scale to [0, precision].","triggerScenarios":"Calling ColumnType.decimal(precision, scale) with precision < 1 or > 76 — e.g. decimal(0,0), decimal(100,5), or precision parsed from a non-ClickHouse DDL like DECIMAL(100,10).","commonSituations":"Translating MySQL/Postgres DECIMAL definitions whose precision exceeds 76 digits; zero/negative sentinel defaults from missing config; regex DDL parsing grabbing wrong digits.","solutions":["Validate precision to [1, 76] (and scale to [0, precision]) before constructing the ColumnType.","Cap oversized precisions at 76, accepting possible loss of significance, or use Float64.","Fix DDL translation logic to map source precisions into the ClickHouse-valid range.","Check config defaults so unset precision doesn't arrive as 0 or negative."],"exampleFix":"// before\nColumnType t = TableSchema.ColumnType.decimal(100, 10); // precision > 76\n// after\nint p = Math.min(76, Math.max(1, srcPrecision));\nint s = Math.min(p, Math.max(0, srcScale));\nColumnType t = TableSchema.ColumnType.decimal(p, s);","handlingStrategy":"validation","validationCode":"int validDecimalPrecision(int precision) {\n  if (precision < 1 || precision > 76) {\n    throw new IllegalArgumentException(\"Decimal precision must be in [1, 76]: \" + precision);\n  }\n  return precision;\n}\n// call: TableSchema.ColumnType.decimal(validDecimalPrecision(p), scale)","typeGuard":null,"tryCatchPattern":"try {\n  ColumnType t = TableSchema.ColumnType.decimal(precision, scale);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"precision must be in [1, 76]\")) {\n    throw new SchemaMappingException(\"Source Decimal precision \" + precision + \" exceeds ClickHouse's 76-digit limit\");\n  }\n  throw e;\n}","preventionTips":["When translating other databases' DECIMAL types, clamp or reject precision > 76.","Remember the paired rule: 0 <= scale <= precision.","Use Float64 when full arbitrary precision isn't required.","Validate precision/scale pairs when building schemas from configuration files."],"tags":["clickhouse","schema","decimal","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"}