{"record":{"id":"76b0a39fb1f06474","repo":"apache/cassandra","slug":"aggregate-name-s-is-invalid","errorCode":null,"errorMessage":"Aggregate name '%s' is invalid","messagePattern":"Aggregate name '(.+?)' is invalid","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateAggregateStatement.java","lineNumber":109,"sourceCode":"        this.rawInitialValue = rawInitialValue;\n        this.orReplace = orReplace;\n        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    @Override\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        if (!FunctionName.isNameValid(aggregateName))\n            throw ire(\"Aggregate name '%s' is invalid\", aggregateName);\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 (!rawStateType.isImplicitlyFrozen() && rawStateType.isFrozen())\n            throw ire(\"State type '%s' cannot be frozen; remove frozen<> modifier from '%s'\", rawStateType, rawStateType);\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        /*\n         * Resolve the state function\n         */\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateAggregateStatement.java#L91-L127","documentation":"Thrown while applying a CREATE AGGREGATE statement when the aggregate name fails FunctionName.isNameValid(). This is a generic name-validity guard: it fires when the identifier contains characters outside those permitted by SchemaConstants or exceeds the maximum identifier length, so the statement is rejected before the aggregate is created in the schema.","triggerScenarios":"CREATE AGGREGATE with a name containing characters outside the accepted set (e.g. invalid characters, empty, or quoted names failing FunctionName.isNameValid).","commonSituations":"Programmatic DDL generation embedding unvalidated user input into aggregate names; names with dots, spaces, or non-ASCII characters.","solutions":["Rename the aggregate to a valid identifier (letters, digits, underscore, not starting with a digit)","Quote the name properly if case-sensitive naming is intended and allowed","Sanitize generated names before building the DDL"],"exampleFix":"// before\nCREATE AGGREGATE ks.my-aggregate(int) ...\n// after\nCREATE AGGREGATE ks.my_aggregate(int) ...","handlingStrategy":"validation","validationCode":"boolean validName = java.util.regex.Pattern.matches(\"[a-zA-Z_][a-zA-Z0-9_]*\", aggName);\nif (!validName) throw new IllegalArgumentException(\"Invalid aggregate name: \" + aggName);","typeGuard":"function isValidIdentifier(name) { return typeof name === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name); }","tryCatchPattern":"try { session.execute(String.format(\"CREATE AGGREGATE %s.%s ...\", ks, name)); }\ncatch (InvalidRequestException e) { if (e.getMessage().contains(\"is invalid\")) sanitizeAndRetry(name); else throw e; }","preventionTips":["Sanitize identifiers generated from user input","Quote case-sensitive names and validate against allowed characters","Add unit tests for name generation with edge-case inputs"],"tags":["cql","aggregate","naming","validation"],"backgroundTag":"invalid-identifier-format","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"}