prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Lower must be <= upper

What it means

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.

Source

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

        double trueAvg = state.getSum() / state.getCount();
        double noisyAvg = trueAvg + noise;

        DOUBLE.writeDouble(out, noisyAvg);
    }

    /**
     * Clip value to [lower, upper] range
     */
    public static double clip(double value, double lower, double upper)
    {
        return Math.max(lower, Math.min(upper, value));
    }

    public static void checkLowerUpper(Double lower, Double upper)
    {
        if (lower != null && upper != null) {
            if (upper < lower) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Lower must be <= upper");
            }
            return;
        }
        if (lower == null && upper == null) {
            return;
        }

        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Lower and upper should either both null or both non-null");
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Swap the arguments so lower <= upper.
  2. If bounds are computed, normalize them: least(lo_expr, hi_expr) and greatest(lo_expr, hi_expr).
  3. Validate upstream data/parameters so bound columns are ordered correctly.
  4. Pass null for a bound only when it is intentionally unbounded, otherwise keep both non-null and ordered.

Example fix

// before
SELECT noisy_count_and_sum_agg(x, 0.5, hi, lo) FROM t; -- hi < lo possible
// after
SELECT noisy_count_and_sum_agg(x, 0.5, least(lo, hi), greatest(lo, hi)) FROM t;
Defensive patterns

Strategy: validation

Validate before calling

SELECT noisy_count_and_sum_agg(x, 0.5, least(lo, hi), greatest(lo, hi)) FROM t;

Type guard

boolean isValidBounds(Double lower, Double upper) {
    if (lower == null && upper == null) return true;
    if (lower == null || upper == null) return true;
    return lower <= upper;
}

Prevention

When it happens

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

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

Related errors


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