{"record":{"id":"13e49ac5afde729d","repo":"prestodb/presto","slug":"table-function-missing-argument","errorCode":"TABLE_FUNCTION_MISSING_ARGUMENT","errorMessage":"Missing argument: ","messagePattern":"Missing argument: ","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":2032,"sourceCode":"        private ArgumentAnalysis analyzeArgument(ArgumentSpecification argumentSpecification, TableFunctionArgument argument, Optional<Scope> scope)\n        {\n            String actualType = getArgumentTypeString(argument);\n            switch (argumentSpecification.getArgumentType()) {\n                case TableArgumentSpecification.argumentType:\n                    return analyzeTableArgument(argument, (TableArgumentSpecification) argumentSpecification, scope, actualType);\n                case DescriptorArgumentSpecification.argumentType:\n                    return analyzeDescriptorArgument(argument, (DescriptorArgumentSpecification) argumentSpecification, actualType);\n                case ScalarArgumentSpecification.argumentType:\n                    return analyzeScalarArgument(argument, argumentSpecification, actualType);\n                default:\n                    throw new IllegalStateException(\"Unexpected argument specification: \" + argumentSpecification.getClass().getSimpleName());\n            }\n        }\n\n        private Argument analyzeDefault(ArgumentSpecification argumentSpecification, Node errorLocation)\n        {\n            if (argumentSpecification.isRequired()) {\n                throw new SemanticException(TABLE_FUNCTION_MISSING_ARGUMENT, errorLocation, \"Missing argument: \" + argumentSpecification.getName());\n            }\n\n            checkArgument(!(argumentSpecification instanceof TableArgumentSpecification), \"invalid table argument specification: default set\");\n\n            if (argumentSpecification instanceof DescriptorArgumentSpecification) {\n                return DescriptorArgument.builder()\n                        .descriptor((Descriptor) argumentSpecification.getDefaultValue())\n                        .build();\n            }\n            if (argumentSpecification instanceof ScalarArgumentSpecification) {\n                return ScalarArgument.builder()\n                        .type(((ScalarArgumentSpecification) argumentSpecification).getType())\n                        .value(argumentSpecification.getDefaultValue())\n                        .build();\n            }\n\n            throw new IllegalStateException(\"Unexpected argument specification: \" + argumentSpecification.getClass().getSimpleName());\n        }","sourceCodeStart":2014,"sourceCodeEnd":2050,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L2014-L2050","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Supply the required argument named in the message to the TABLE() invocation.","Verify the function's argument specifications to see which arguments are required vs. defaulted.","If the argument should be optional, this is a function-definition issue: give the ArgumentSpecification a default value."],"exampleFix":"// before\nSELECT * FROM TABLE(execute_descriptor_fn());\n// after\nSELECT * FROM TABLE(execute_descriptor_fn(DESC => DESCRIPTOR(x)));","handlingStrategy":"validation","validationCode":"// Ensure all required specs have a corresponding named argument\nSet<String> passed = args.stream().map(a -> a.getName().orElseThrow().getCanonicalValue()).collect(toSet());\nspecifications.stream()\n    .filter(ArgumentSpecification::isRequired)\n    .forEach(s -> checkArgument(passed.contains(s.getName()), \"Missing required argument %s\", s.getName()));","typeGuard":"boolean allRequiredPresent(List<TableFunctionArgument> args, List<ArgumentSpecification> specs) {\n    Set<String> names = args.stream().map(a -> a.getName().orElseThrow().getCanonicalValue()).collect(toSet());\n    return specs.stream().filter(ArgumentSpecification::isRequired)\n        .allMatch(s -> names.contains(s.getName()));\n}","tryCatchPattern":"try {\n    session.execute(query);\n} catch (SemanticException e) {\n    if (e.getCode() == TABLE_FUNCTION_MISSING_ARGUMENT) {\n        // parse e.getMessage() after \"Missing argument: \" to get the required name and re-issue the query\n    }\n}","preventionTips":["List all required arguments explicitly, even when defaults seem likely.","Pin the Presto version and re-check optional/required status after upgrades.","Build invocation strings from the function's specification list, not by hand."],"tags":["sql","table-function","missing-argument","semantic-analysis"],"backgroundTag":"missing-required-argument","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"}