prestodb/presto · error · SemanticException

TABLE_FUNCTION_MISSING_ARGUMENT

TABLE_FUNCTION_MISSING_ARGUMENT

Error message

Missing argument: 

What it means

After the invocation loop applies defaults for unprovided arguments, analyzeDefault checks whether a still-unmatched specification is required. Required arguments cannot get a default, so TABLE_FUNCTION_MISSING_ARGUMENT is thrown naming the missing argument. It ensures every mandatory table function argument is supplied.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java:2032

        private ArgumentAnalysis analyzeArgument(ArgumentSpecification argumentSpecification, TableFunctionArgument argument, Optional<Scope> scope)
        {
            String actualType = getArgumentTypeString(argument);
            switch (argumentSpecification.getArgumentType()) {
                case TableArgumentSpecification.argumentType:
                    return analyzeTableArgument(argument, (TableArgumentSpecification) argumentSpecification, scope, actualType);
                case DescriptorArgumentSpecification.argumentType:
                    return analyzeDescriptorArgument(argument, (DescriptorArgumentSpecification) argumentSpecification, actualType);
                case ScalarArgumentSpecification.argumentType:
                    return analyzeScalarArgument(argument, argumentSpecification, actualType);
                default:
                    throw new IllegalStateException("Unexpected argument specification: " + argumentSpecification.getClass().getSimpleName());
            }
        }

        private Argument analyzeDefault(ArgumentSpecification argumentSpecification, Node errorLocation)
        {
            if (argumentSpecification.isRequired()) {
                throw new SemanticException(TABLE_FUNCTION_MISSING_ARGUMENT, errorLocation, "Missing argument: " + argumentSpecification.getName());
            }

            checkArgument(!(argumentSpecification instanceof TableArgumentSpecification), "invalid table argument specification: default set");

            if (argumentSpecification instanceof DescriptorArgumentSpecification) {
                return DescriptorArgument.builder()
                        .descriptor((Descriptor) argumentSpecification.getDefaultValue())
                        .build();
            }
            if (argumentSpecification instanceof ScalarArgumentSpecification) {
                return ScalarArgument.builder()
                        .type(((ScalarArgumentSpecification) argumentSpecification).getType())
                        .value(argumentSpecification.getDefaultValue())
                        .build();
            }

            throw new IllegalStateException("Unexpected argument specification: " + argumentSpecification.getClass().getSimpleName());
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Supply the required argument named in the message to the TABLE() invocation.
  2. Verify the function's argument specifications to see which arguments are required vs. defaulted.
  3. If the argument should be optional, this is a function-definition issue: give the ArgumentSpecification a default value.

Example fix

// before
SELECT * FROM TABLE(execute_descriptor_fn());
// after
SELECT * FROM TABLE(execute_descriptor_fn(DESC => DESCRIPTOR(x)));
Defensive patterns

Strategy: validation

Validate before calling

// Ensure all required specs have a corresponding named argument
Set<String> passed = args.stream().map(a -> a.getName().orElseThrow().getCanonicalValue()).collect(toSet());
specifications.stream()
    .filter(ArgumentSpecification::isRequired)
    .forEach(s -> checkArgument(passed.contains(s.getName()), "Missing required argument %s", s.getName()));

Type guard

boolean allRequiredPresent(List<TableFunctionArgument> args, List<ArgumentSpecification> specs) {
    Set<String> names = args.stream().map(a -> a.getName().orElseThrow().getCanonicalValue()).collect(toSet());
    return specs.stream().filter(ArgumentSpecification::isRequired)
        .allMatch(s -> names.contains(s.getName()));
}

Try / catch

try {
    session.execute(query);
} catch (SemanticException e) {
    if (e.getCode() == TABLE_FUNCTION_MISSING_ARGUMENT) {
        // parse e.getMessage() after "Missing argument: " to get the required name and re-issue the query
    }
}

Prevention

When it happens

Trigger: Invoking a table function without supplying one of its required arguments, e.g. `TABLE(execute_descriptor_fn())` when the function requires a DESCRIPTOR argument, or omitting a required scalar parameter like a schema/table name argument.

Common situations: Reading function docs from an older version where an argument was optional; forgetting a required argument when the call is built dynamically; SQL generator producing partial argument lists.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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