{"record":{"id":"3f01654fa9a1edf7","repo":"apache/beam","slug":"decimal-scale-must-be-in-0-got","errorCode":null,"errorMessage":"Decimal scale must be in [0, ], got ","messagePattern":"Decimal scale must be in \\[0, \\], 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":350,"sourceCode":"\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)\n          .enumValues(enumValues)\n          .build();\n    }\n","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/TableSchema.java#L332-L368","documentation":"TableSchema.decimal(precision, scale) builds a ClickHouse DECIMAL column type and validates that precision is in [1, 76] and scale is in [0, precision] before constructing the ColumnType. This IllegalArgumentException means the supplied scale was negative or larger than the declared precision, which ClickHouse cannot represent as Decimal(P, S).","triggerScenarios":"Calling TableSchema.decimal(precision, scale) with scale < 0, or with scale > precision (e.g. decimal(10, 11)), or with a negative precision that passes/fails the earlier precision check first.","commonSituations":"Transposing the two arguments (calling decimal(scale, precision)), computing precision/scale from user input or schema inference code where scale can exceed precision, or hand-editing a schema definition.","solutions":["Ensure 1 <= precision <= 76 and 0 <= scale <= precision before calling decimal().","Check argument order — decimal takes (precision, scale); swap the values if you passed them reversed.","If deriving from upstream metadata, clamp or validate: Math.max(0, Math.min(scale, precision))."],"exampleFix":"// before\nColumnType type = TableSchema.decimal(10, 11); // scale > precision -> throws\n// after\nColumnType type = TableSchema.decimal(11, 10); // valid: scale <= precision","handlingStrategy":"validation","validationCode":"if (precision < 1 || precision > 76) throw new IllegalArgumentException(\"precision out of range: \" + precision);\nif (scale < 0 || scale > precision) throw new IllegalArgumentException(\"scale out of range: \" + scale);\nTableSchema.ColumnType type = TableSchema.decimal(precision, scale);","typeGuard":null,"tryCatchPattern":"try {\n  TableSchema.decimal(precision, scale);\n} catch (IllegalArgumentException e) {\n  // fall back to clamped values or report schema build failure\n}","preventionTips":["Remember the argument order is (precision, scale).","Clamp scale to [0, precision] when deriving values from external metadata.","Add a unit test for schema-building code that constructs DECIMAL columns."],"tags":["clickhouse","schema","validation","decimal"],"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"}