prestodb/presto · error · IllegalArgumentException

Invalid weight:

Error message

Invalid weight: 

What it means

SplitWeight.fromProportion converts a relative proportion (fraction of total work) into a SplitWeight. It throws IllegalArgumentException("Invalid weight: ...") when the proportion is <= 0 or not finite (NaN or infinite).

Source

Thrown at presto-spi/src/main/java/com/facebook/presto/spi/SplitWeight.java:95

        }
        return BigDecimal.valueOf(value, -UNIT_SCALE).stripTrailingZeros().toPlainString();
    }

    @JsonCreator
    public static SplitWeight fromRawValue(long value)
    {
        return value == UNIT_VALUE ? STANDARD_WEIGHT : new SplitWeight(value);
    }

    public static SplitWeight standard()
    {
        return STANDARD_WEIGHT;
    }

    public static SplitWeight fromProportion(double weight)
    {
        if (weight <= 0 || !Double.isFinite(weight)) {
            throw new IllegalArgumentException("Invalid weight: " + weight);
        }
        // Must round up to avoid small weights rounding to 0
        return fromRawValue((long) Math.ceil(weight * UNIT_VALUE));
    }

    public static long rawValueForStandardSplitCount(int splitCount)
    {
        if (splitCount < 0) {
            throw new IllegalArgumentException("splitCount must be >= 0, found: " + splitCount);
        }
        return multiplyExact(splitCount, UNIT_VALUE);
    }

    public static <T> long rawValueSum(Collection<T> collection, Function<T, SplitWeight> getter)
    {
        long sum = 0;
        for (T item : collection) {
            long value = getter.apply(item).getRawValue();

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Clamp the proportion to a small positive value before calling, e.g. Math.max(proportion, 1e-9)
  2. Fix the upstream computation producing NaN/infinity (check for division by zero)
  3. Fall back to SplitWeight.STANDARD_WEIGHT when the computed proportion is not a valid positive finite number

Example fix

// before
SplitWeight w = SplitWeight.fromProportion(ratio); // ratio may be NaN
// after
SplitWeight w = (ratio > 0 && Double.isFinite(ratio)) ? SplitWeight.fromProportion(ratio) : SplitWeight.STANDARD_WEIGHT;
Defensive patterns

Strategy: validation

Validate before calling

boolean valid = weight > 0 && Double.isFinite(weight);

Prevention

When it happens

Trigger: Calling SplitWeight.fromProportion(0), fromProportion(-0.5), fromProportion(Double.NaN), or fromProportion(Double.POSITIVE_INFINITY).

Common situations: Computing a weight from a ratio whose denominator was 0 (yielding NaN/Infinity); uninitialized or defaulted weighting factors of 0; averaging weights over an empty set.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/8bf6c7cce598ec8f. Report an issue: GitHub.