prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Noise scale must be >= 0

What it means

NoisyCountAggregationUtils.checkNoiseScale validates the noise_scale parameter of noisy count aggregations (e.g. noisy_count_agg). The noise scale is a standard deviation applied to Gaussian noise, so a negative value is meaningless and throws INVALID_FUNCTION_ARGUMENT. It is called from updateState and combineStates whenever the aggregation processes input or merges state.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/noisyaggregation/NoisyCountAggregationUtils.java:86

        long noisyCount = computeNoisyCount(state, noise);
        BIGINT.writeLong(out, noisyCount);
    }

    public static double getNoise(NoisyCountState state)
    {
        Random random = SecureRandomGeneration.getNonBlocking();
        if (!state.isNullRandomSeed()) {
            random = new Random(state.getRandomSeed());
        }

        double noiseSdv = state.getNoiseScale();
        return random.nextGaussian() * noiseSdv;
    }

    public static void checkNoiseScale(double noiseScale)
    {
        if (noiseScale < 0) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Noise scale must be >= 0");
        }
    }

    public static long computeNoisyCount(NoisyCountState state, double noise)
    {
        long trueCount = state.getCount();
        double noisyCount = trueCount + noise;
        double noisyCountFixedSign = Math.max(noisyCount, 0);  // count should always be >= 0
        return Math.round(noisyCountFixedSign);
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Pass a non-negative noise_scale (0 is allowed and means deterministic count).
  2. If computed, clamp it: greatest(noise_expr, 0.0).
  3. Fix upstream data so the parameter column contains no negative values (or filter those rows).
  4. Use try_cast / CASE to guard against sentinel negatives before aggregation.

Example fix

// before
SELECT noisy_count_agg(x, noise_scale) FROM t; -- noise_scale can be negative
// after
SELECT noisy_count_agg(x, greatest(noise_scale, 0.0)) FROM t;
Defensive patterns

Strategy: validation

Validate before calling

SELECT noisy_count_agg(x, greatest(COALESCE(noise_scale, 0.0), 0.0)) FROM t;

Type guard

boolean isValidNoiseScale(Double noiseScale) {
    return noiseScale != null && noiseScale >= 0;
}

Prevention

When it happens

Trigger: Calling noisy_count_agg / similar noisy aggregations with noise_scale < 0, whether a literal or a computed/existing column value.

Common situations: Sign errors in computed noise parameters; passing a delta/epsilon-derived formula that can go negative; NULL-handling logic returning -1 as a sentinel; copying a parameters table with a wrong-signed column.

Related errors


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