{"record":{"id":"7ffa1af903ecfe37","repo":"prestodb/presto","slug":"invalid-function-argument-7ffa1a","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Lower must be <= upper","messagePattern":"Lower must be <= upper","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/noisyaggregation/NoisyCountAndSumAggregationUtils.java","lineNumber":99,"sourceCode":"        double trueAvg = state.getSum() / state.getCount();\n        double noisyAvg = trueAvg + noise;\n\n        DOUBLE.writeDouble(out, noisyAvg);\n    }\n\n    /**\n     * Clip value to [lower, upper] range\n     */\n    public static double clip(double value, double lower, double upper)\n    {\n        return Math.max(lower, Math.min(upper, value));\n    }\n\n    public static void checkLowerUpper(Double lower, Double upper)\n    {\n        if (lower != null && upper != null) {\n            if (upper < lower) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Lower must be <= upper\");\n            }\n            return;\n        }\n        if (lower == null && upper == null) {\n            return;\n        }\n\n        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Lower and upper should either both null or both non-null\");\n    }\n}\n","sourceCodeStart":81,"sourceCodeEnd":110,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/noisyaggregation/NoisyCountAndSumAggregationUtils.java#L81-L110","documentation":"NoisyCountAndSumAggregationUtils.checkLowerUpper validates the optional lower/upper clamping bounds for noisy count-and-sum aggregations. When both are provided and upper < lower the range is invalid, throwing INVALID_FUNCTION_ARGUMENT. Nulls are allowed (each bound is optional) but a provided pair must satisfy lower <= upper.","triggerScenarios":"Calling noisy count/sum aggregations with both lower and upper bounds where upper evaluates to a value less than lower (e.g. lower=10, upper=5).","commonSituations":"Swapping the two bound arguments at the call site; computed bounds from columns where the ordering is not guaranteed (e.g. percentile columns p05/p95 mislabeled); copy-paste errors in parameter tables.","solutions":["Swap the arguments so lower <= upper.","If bounds are computed, normalize them: least(lo_expr, hi_expr) and greatest(lo_expr, hi_expr).","Validate upstream data/parameters so bound columns are ordered correctly.","Pass null for a bound only when it is intentionally unbounded, otherwise keep both non-null and ordered."],"exampleFix":"// before\nSELECT noisy_count_and_sum_agg(x, 0.5, hi, lo) FROM t; -- hi < lo possible\n// after\nSELECT noisy_count_and_sum_agg(x, 0.5, least(lo, hi), greatest(lo, hi)) FROM t;","handlingStrategy":"validation","validationCode":"SELECT noisy_count_and_sum_agg(x, 0.5, least(lo, hi), greatest(lo, hi)) FROM t;","typeGuard":"boolean isValidBounds(Double lower, Double upper) {\n    if (lower == null && upper == null) return true;\n    if (lower == null || upper == null) return true;\n    return lower <= upper;\n}","tryCatchPattern":null,"preventionTips":["Normalize computed bounds with least/greatest before passing them.","Double-check argument order when bounds are literals.","Add schema-level checks ensuring bound columns satisfy lo <= hi."],"tags":["aggregation","differential-privacy","invalid-argument","bounds"],"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"}