{"record":{"id":"a7baf8374f593cd6","repo":"apache/cassandra","slug":"duplicate-argument-names-for-given-function-s-wit","errorCode":null,"errorMessage":"Duplicate argument names for given function %s with argument names %s","messagePattern":"Duplicate argument names for given function (.+?) with argument names (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateFunctionStatement.java","lineNumber":106,"sourceCode":"    @Override\n    public boolean compatibleWith(ClusterMetadata metadata)\n    {\n        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);\n    }\n\n    // TODO: replace affected aggregates !!\n    public Keyspaces apply(ClusterMetadata metadata)\n    {\n        if (ifNotExists && orReplace)\n            throw ire(\"Cannot use both 'OR REPLACE' and 'IF NOT EXISTS' directives\");\n\n        UDFunction.assertUdfsEnabled(language);\n\n        if (!FunctionName.isNameValid(functionName))\n            throw ire(\"Function name '%s' is invalid\", functionName);\n\n        if (new HashSet<>(argumentNames).size() != argumentNames.size())\n            throw ire(\"Duplicate argument names for given function %s with argument names %s\", functionName, argumentNames);\n\n        rawArgumentTypes.stream()\n                        .filter(raw -> !raw.isImplicitlyFrozen() && raw.isFrozen())\n                        .findFirst()\n                        .ifPresent(t -> { throw ire(\"Argument '%s' cannot be frozen; remove frozen<> modifier from '%s'\", t, t); });\n\n        if (!rawReturnType.isImplicitlyFrozen() && rawReturnType.isFrozen())\n            throw ire(\"Return type '%s' cannot be frozen; remove frozen<> modifier from '%s'\", rawReturnType, rawReturnType);\n\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n        if (null == keyspace)\n            throw ire(\"Keyspace '%s' doesn't exist\", keyspaceName);\n\n        List<AbstractType<?>> argumentTypes =\n            rawArgumentTypes.stream()\n                            .map(t -> t.prepare(keyspaceName, keyspace.types).getType().udfType())\n                            .collect(toList());","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateFunctionStatement.java#L88-L124","documentation":"CREATE FUNCTION validation rejects a function whose argument names contain duplicates. Cassandra requires each argument of a user-defined function to have a unique identifier so arguments can be referenced unambiguously (e.g. in language bodies and state functions). The check compares the size of the argument-name set against the list size in CreateFunctionStatement.apply.","triggerScenarios":"Executing CREATE [OR REPLACE] FUNCTION with two arguments sharing the same declared name, e.g. CREATE FUNCTION f(a int, a text).","commonSituations":"Copy-pasted function signatures where a parameter name was forgotten to be renamed; generated DDL scripts producing duplicated parameter names; typos that coincidentally match an existing parameter.","solutions":["Rename the duplicated argument so every argument name in the signature is unique","Review the full argument list in the CREATE FUNCTION statement for accidental repeats","If DDL is generated, fix the generator to enforce unique parameter names"],"exampleFix":"// before\nCREATE FUNCTION ks.f(a int, a text) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return 0;';\n// after\nCREATE FUNCTION ks.f(a int, b text) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return 0;';","handlingStrategy":"validation","validationCode":"Set<String> names = new HashSet<>(argumentNames);\nif (names.size() != argumentNames.size()) throw new IllegalArgumentException(\"Duplicate argument names: \" + argumentNames);","typeGuard":"boolean hasUniqueArgNames(List<String> names) { return new HashSet<>(names).size() == names.size(); }","tryCatchPattern":"try { session.execute(createFunctionStmt); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Duplicate argument names\")) { /* fix signature and retry */ } else throw e; }","preventionTips":["Enforce unique parameter names in any DDL generator","Review function signatures after copy-paste edits","Add CI linting for CQL function definitions"],"tags":["cql","udf","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}