apache/cassandra · error · InvalidRequestException

Aggregate name ' ' is invalid

Error message

Aggregate name '%s' is invalid

What it means

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.

Solutions

  1. Rename the aggregate to a valid identifier (letters, digits, underscore, not starting with a digit)
  2. Quote the name properly if case-sensitive naming is intended and allowed
  3. Sanitize generated names before building the DDL

Example fix

// before
CREATE AGGREGATE ks.my-aggregate(int) ...
// after
CREATE AGGREGATE ks.my_aggregate(int) ...
Defensive patterns

Strategy: validation

Validate before calling

boolean validName = java.util.regex.Pattern.matches("[a-zA-Z_][a-zA-Z0-9_]*", aggName);
if (!validName) throw new IllegalArgumentException("Invalid aggregate name: " + aggName);

Type guard

function isValidIdentifier(name) { return typeof name === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name); }

Try / catch

try { session.execute(String.format("CREATE AGGREGATE %s.%s ...", ks, name)); }
catch (InvalidRequestException e) { if (e.getMessage().contains("is invalid")) sanitizeAndRetry(name); else throw e; }

Prevention

When it happens

Trigger: CREATE AGGREGATE with a name containing characters outside the accepted set (e.g. invalid characters, empty, or quoted names failing FunctionName.isNameValid).

Common situations: Programmatic DDL generation embedding unvalidated user input into aggregate names; names with dots, spaces, or non-ASCII characters.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/76b0a39fb1f06474. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateAggregateStatement.java:109

        this.rawInitialValue = rawInitialValue;
        this.orReplace = orReplace;
        this.ifNotExists = ifNotExists;
    }

    @Override
    public boolean compatibleWith(ClusterMetadata metadata)
    {
        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);
    }

    @Override
    public Keyspaces apply(ClusterMetadata metadata)
    {
        if (ifNotExists && orReplace)
            throw ire("Cannot use both 'OR REPLACE' and 'IF NOT EXISTS' directives");

        if (!FunctionName.isNameValid(aggregateName))
            throw ire("Aggregate name '%s' is invalid", aggregateName);

        rawArgumentTypes.stream()
                        .filter(raw -> !raw.isImplicitlyFrozen() && raw.isFrozen())
                        .findFirst()
                        .ifPresent(t -> { throw ire("Argument '%s' cannot be frozen; remove frozen<> modifier from '%s'", t, t); });

        if (!rawStateType.isImplicitlyFrozen() && rawStateType.isFrozen())
            throw ire("State type '%s' cannot be frozen; remove frozen<> modifier from '%s'", rawStateType, rawStateType);

        Keyspaces schema = metadata.schema.getKeyspaces();
        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
        if (null == keyspace)
            throw ire("Keyspace '%s' doesn't exist", keyspaceName);

        /*
         * Resolve the state function
         */

View on GitHub (pinned to 88fd0f6a0e)