prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Unsupported number of arguments: %s

What it means

getInputTypes maps the aggregation's argument count (arity) to input types: 1 arg (value), 2 args (value, weight), or 3 args (value, weight, accuracy). Any other arity is rejected with INVALID_FUNCTION_ARGUMENT because the function signature is undefined for it.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/StatisticalDigestAggregationFunction.java:180

                classLoader);
        return new BuiltInAggregationFunctionImplementation(name, inputTypes, ImmutableList.of(intermediateType), outputType,
                true, true, metadata, accumulatorClass, groupedAccumulatorClass);
    }

    private static List<Type> getInputTypes(Type valueType, int arity)
    {
        switch (arity) {
            case 1:
                // weight and accuracy unspecified
                return ImmutableList.of(valueType);
            case 2:
                // weight specified, accuracy unspecified
                return ImmutableList.of(valueType, BIGINT);
            case 3:
                // weight and accuracy specified
                return ImmutableList.of(valueType, BIGINT, DOUBLE);
            default:
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Unsupported number of arguments: %s", arity));
        }
    }

    private MethodHandle getInputMethodHandle(Type valueType, int arity)
    {
        switch (type) {
            case TDIGEST:
                return getTDigestInputMethodHandle(valueType, arity);
            case QDIGEST:
                return getQuantileDigestInputMethodHandle(valueType, arity);
            default:
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("%s must be a statistical digest", type));
        }
    }

    private MethodHandle getTDigestInputMethodHandle(Type valueType, int arity)
    {
        final MethodHandle inputFunction;

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Call the aggregation with 1, 2, or 3 arguments only (value, value+weight, or value+weight+accuracy).
  2. Check the function signature in the catalog/registry to confirm accepted arities.
  3. If this is a custom binding, fix the arity passed to the aggregation metadata builder.

Example fix

// before
qdigest_agg(value, weight, accuracy, extra)
// after
qdigest_agg(value, weight, accuracy)
Defensive patterns

Strategy: validation

Validate before calling

if (args.size() < 1 || args.size() > 3) throw new IllegalArgumentException("digest aggregation accepts 1-3 arguments");

Try / catch

try { runQuery(sql); } catch (PrestoException e) { if (e.getErrorCode().getName().equals("INVALID_FUNCTION_ARGUMENT") && e.getMessage().startsWith("Unsupported number of arguments")) { fixArity(sql); } else throw e; }

Prevention

When it happens

Trigger: Registering or invoking the statistical digest aggregation with 0, or more than 3 arguments, so the switch in getInputTypes falls to default.

Common situations: Typos in SQL aggregation calls passing extra arguments, or custom function registrations built with wrong parameter counts.

Related errors


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