{"record":{"id":"2db8e9e87dd11c4a","repo":"prestodb/presto","slug":"table-function-invalid-copartitioning","errorCode":"TABLE_FUNCTION_INVALID_COPARTITIONING","errorMessage":"No table argument found for name: ","messagePattern":"No table argument found for name: ","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":2277,"sourceCode":"            Set<String> referencedArguments = new HashSet<>();\n            for (List<QualifiedName> nameList : copartitioning) {\n                ImmutableList.Builder<TableArgumentAnalysis> copartitionListBuilder = ImmutableList.builder();\n\n                // resolve copartition tables as references to table arguments\n                for (QualifiedName name : nameList) {\n                    Collection<TableArgumentAnalysis> candidates = emptyList();\n                    if (name.getParts().size() == 1) {\n                        // try to match unqualified name. it might be a reference to a CTE or an aliased relation\n                        candidates = unqualifiedInputs.get(name);\n                    }\n                    if (candidates.isEmpty()) {\n                        // qualify the name using current schema and catalog\n                        // Since we lost the Identifier context, create a new one here\n                        QualifiedObjectName fullyQualifiedName = createQualifiedObjectName(session, new Identifier(name.getOriginalParts().get(0).getValue()), name, metadata);\n                        candidates = qualifiedInputs.get(QualifiedName.of(fullyQualifiedName.getCatalogName(), fullyQualifiedName.getSchemaName(), fullyQualifiedName.getObjectName()));\n                    }\n                    if (candidates.isEmpty()) {\n                        throw new SemanticException(TABLE_FUNCTION_INVALID_COPARTITIONING, name.getOriginalParts().get(0), \"No table argument found for name: \" + name);\n                    }\n                    if (candidates.size() > 1) {\n                        throw new SemanticException(TABLE_FUNCTION_INVALID_COPARTITIONING, name.getOriginalParts().get(0), \"Ambiguous reference: multiple table arguments found for name: \" + name);\n                    }\n                    TableArgumentAnalysis argument = candidates.stream().collect(onlyElement());\n                    if (!referencedArguments.add(argument.getArgumentName())) {\n                        // multiple references to argument in COPARTITION clause are implicitly prohibited by\n                        // ISO/IEC TR REPORT 19075-7, p.33, Feature B203, “More than one copartition specification”\n                        throw new SemanticException(TABLE_FUNCTION_INVALID_COPARTITIONING, name.getOriginalParts().get(0), \"Multiple references to table argument: %s in COPARTITION clause\", name);\n                    }\n                    copartitionListBuilder.add(argument);\n                }\n                List<TableArgumentAnalysis> copartitionList = copartitionListBuilder.build();\n\n                // analyze partitioning columns\n                copartitionList.stream()\n                        .filter(argument -> !argument.getPartitionBy().isPresent())\n                        .findFirst().ifPresent(unpartitioned -> {","sourceCodeStart":2259,"sourceCodeEnd":2295,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L2259-L2295","documentation":"A COPARTITIONING clause named a table argument that does not exist among the table arguments of the current table function invocation (after qualifying the name against catalog/schema). The analyzer looks up the referenced name in the map of qualified table-argument inputs and throws TABLE_FUNCTION_INVALID_COPARTITIONING when the candidate set is empty.","triggerScenarios":"Writing COPARTITIONING(a, b) where 'b' (or its qualified name) does not match any table argument name passed in the same TABLE(...) invocation, or the qualifier (catalog/schema/table alias) does not resolve.","commonSituations":"Typos in the copartitioning names; referencing the underlying table name instead of the argument alias; using an unqualified name when the argument was registered under a qualified name, or after renaming an argument.","solutions":["Match the copartitioning name exactly to a table argument name in the same invocation.","Use the same qualification level (either both qualified or both simple names).","Remove stale references left over from renaming arguments.","Confirm each referenced relation is actually passed as a table argument, not just present in the query."],"exampleFix":"// before\nTABLE(join_fn(l => orders, r => customers) COPARTITIONING (orders, cust))\n\n// after\nTABLE(join_fn(l => orders, r => customers) COPARTITIONING (l, r))","handlingStrategy":"validation","validationCode":"// Ensure every COPARTITIONING name matches a table argument in the same invocation\nSet<String> argumentNames = tableInvocationArguments.keySet(); // e.g. {\"l\", \"r\"}\nfor (String name : copartitioningNames) {\n    String simple = name.contains(\".\") ? name.substring(name.lastIndexOf('.') + 1) : name;\n    if (!argumentNames.contains(simple)) {\n        throw new IllegalArgumentException(\"COPARTITIONING references unknown table argument: \" + name);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reference table arguments by their argument alias, not the underlying table name.","Keep qualification of copartitioning names consistent with the argument names.","Re-check the COPARTITIONING list after renaming any table arguments."],"tags":["sql","table-functions","copartitioning","name-resolution"],"backgroundTag":"table-function-invalid-copartitioning","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"}