{"record":{"id":"b8c676d8ebbea245","repo":"apache/cassandra","slug":"function-name-s-is-invalid","errorCode":null,"errorMessage":"Function name '%s' is invalid","messagePattern":"Function name '(.+?)' is invalid","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateFunctionStatement.java","lineNumber":103,"sourceCode":"        this.ifNotExists = ifNotExists;\n    }\n\n    @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 =","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateFunctionStatement.java#L85-L121","documentation":"Thrown when the function name supplied to CREATE FUNCTION (or CREATE AGGREGATE) fails FunctionName.isNameValid — i.e. it is not a valid Cassandra identifier/keyspace-qualified name under the current naming rules.","triggerScenarios":"CREATE FUNCTION with a name containing illegal characters, starting with a digit, using reserved keywords unquoted, or an empty name.","commonSituations":"Programmatic DDL generation interpolating unvalidated identifiers; names copied from systems with laxer identifier rules; missing quotes around a name that needs quoting.","solutions":["Rename the function to a valid identifier ([a-zA-Z][a-zA-Z0-9_]* pattern, not a reserved keyword).","Wrap a keyword-like or unusual name in double quotes: CREATE FUNCTION ks.\"my-func\"(...).","Validate identifiers in code that generates DDL before executing it.","Fully qualify with a valid keyspace prefix if the intended name included one."],"exampleFix":"// before\nCREATE FUNCTION ks.1st_fn(i int) RETURNS NULL ON NULL INPUT RETURNS int ...;\n// after\nCREATE FUNCTION ks.first_fn(i int) RETURNS NULL ON NULL INPUT RETURNS int ...;","handlingStrategy":"validation","validationCode":"// Java\npublic static boolean isValidFnName(String name) {\n    String[] parts = name.split(\"\\\\.\");\n    if (parts.length > 2) return false;\n    for (String p : parts)\n        if (!p.matches(\"[a-zA-Z][a-zA-Z0-9_]*\")) return false; // or a quoted identifier\n    return true;\n}","typeGuard":"boolean isQuotedOrPlainIdentifier(String s) {\n    return (s.startsWith(\"\\\"\") && s.endsWith(\"\\\"\")) || s.matches(\"[a-zA-Z][a-zA-Z0-9_]*\");\n}","tryCatchPattern":"try { session.execute(ddl); }\ncatch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"is invalid\")) { /* quote the identifier or rename */ }\n    else throw e;\n}","preventionTips":["Validate identifiers at the DDL-generation layer.","Quote keyword-like identifiers with double quotes.","Restrict generated names to [a-zA-Z_][a-zA-Z0-9_]*."],"tags":["cql","naming","identifier"],"backgroundTag":"invalid-identifier","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"}