apache/beam · error · IllegalArgumentException

Decimal scale must be in [0, ], got

Error message

Decimal scale must be in [0, ], got 

What it means

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).

Solutions

  1. Ensure 1 <= precision <= 76 and 0 <= scale <= precision before calling decimal().
  2. Check argument order — decimal takes (precision, scale); swap the values if you passed them reversed.
  3. If deriving from upstream metadata, clamp or validate: Math.max(0, Math.min(scale, precision)).

Example fix

// before
ColumnType type = TableSchema.decimal(10, 11); // scale > precision -> throws
// after
ColumnType type = TableSchema.decimal(11, 10); // valid: scale <= precision
Defensive patterns

Strategy: validation

Validate before calling

if (precision < 1 || precision > 76) throw new IllegalArgumentException("precision out of range: " + precision);
if (scale < 0 || scale > precision) throw new IllegalArgumentException("scale out of range: " + scale);
TableSchema.ColumnType type = TableSchema.decimal(precision, scale);

Try / catch

try {
  TableSchema.decimal(precision, scale);
} catch (IllegalArgumentException e) {
  // fall back to clamped values or report schema build failure
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/3f01654fa9a1edf7. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/TableSchema.java:350

    /**
     * Returns a {@code Decimal(precision, scale)} type.
     *
     * <p>ClickHouse stores {@code Decimal} values as integers of a width chosen from the declared
     * precision: 32 bits for precision 1–9, 64 for 10–18, 128 for 19–38 and 256 for 39–76. The
     * width aliases {@code Decimal32(S)}, {@code Decimal64(S)}, {@code Decimal128(S)} and {@code
     * Decimal256(S)} correspond to precisions 9, 18, 38 and 76.
     *
     * @param precision total number of decimal digits, in {@code [1, 76]}
     * @param scale number of fractional decimal digits, in {@code [0, precision]}
     */
    public static ColumnType decimal(int precision, int scale) {
      if (precision < 1 || precision > 76) {
        throw new IllegalArgumentException(
            "Decimal precision must be in [1, 76], got " + precision);
      }
      if (scale < 0 || scale > precision) {
        throw new IllegalArgumentException(
            "Decimal scale must be in [0, " + precision + "], got " + scale);
      }
      return ColumnType.builder()
          .typeName(TypeName.DECIMAL)
          .nullable(false)
          .precision(precision)
          .scale(scale)
          .build();
    }

    public static ColumnType enum8(Map<String, Integer> enumValues) {
      return ColumnType.builder()
          .typeName(TypeName.ENUM8)
          .nullable(false)
          .enumValues(enumValues)
          .build();
    }

View on GitHub (pinned to 12126d8942)