{"record":{"id":"2fe07cad799a0a18","repo":"prestodb/presto","slug":"invalid-function-argument-2fe07c","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Noise scale must be >= 0","messagePattern":"Noise scale must be >= 0","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/noisyaggregation/NoisyCountAggregationUtils.java","lineNumber":86,"sourceCode":"        long noisyCount = computeNoisyCount(state, noise);\n        BIGINT.writeLong(out, noisyCount);\n    }\n\n    public static double getNoise(NoisyCountState state)\n    {\n        Random random = SecureRandomGeneration.getNonBlocking();\n        if (!state.isNullRandomSeed()) {\n            random = new Random(state.getRandomSeed());\n        }\n\n        double noiseSdv = state.getNoiseScale();\n        return random.nextGaussian() * noiseSdv;\n    }\n\n    public static void checkNoiseScale(double noiseScale)\n    {\n        if (noiseScale < 0) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Noise scale must be >= 0\");\n        }\n    }\n\n    public static long computeNoisyCount(NoisyCountState state, double noise)\n    {\n        long trueCount = state.getCount();\n        double noisyCount = trueCount + noise;\n        double noisyCountFixedSign = Math.max(noisyCount, 0);  // count should always be >= 0\n        return Math.round(noisyCountFixedSign);\n    }\n}\n","sourceCodeStart":68,"sourceCodeEnd":98,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/noisyaggregation/NoisyCountAggregationUtils.java#L68-L98","documentation":"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.","triggerScenarios":"Calling noisy_count_agg / similar noisy aggregations with noise_scale < 0, whether a literal or a computed/existing column value.","commonSituations":"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.","solutions":["Pass a non-negative noise_scale (0 is allowed and means deterministic count).","If computed, clamp it: greatest(noise_expr, 0.0).","Fix upstream data so the parameter column contains no negative values (or filter those rows).","Use try_cast / CASE to guard against sentinel negatives before aggregation."],"exampleFix":"// before\nSELECT noisy_count_agg(x, noise_scale) FROM t; -- noise_scale can be negative\n// after\nSELECT noisy_count_agg(x, greatest(noise_scale, 0.0)) FROM t;","handlingStrategy":"validation","validationCode":"SELECT noisy_count_agg(x, greatest(COALESCE(noise_scale, 0.0), 0.0)) FROM t;","typeGuard":"boolean isValidNoiseScale(Double noiseScale) {\n    return noiseScale != null && noiseScale >= 0;\n}","tryCatchPattern":null,"preventionTips":["Clamp derived noise parameters with greatest(expr, 0.0).","Validate parameter tables for negative sentinel values.","Remember noise_scale = 0 is valid and disables noise."],"tags":["aggregation","differential-privacy","invalid-argument","noisy-aggregation"],"backgroundTag":"invalid-function-arguments","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}