{"record":{"id":"867d3897e372463f","repo":"apache/cassandra","slug":"keyspace-s-doesn-t-exist-867d38","errorCode":null,"errorMessage":"Keyspace '%s' doesn't exist","messagePattern":"Keyspace '(.+?)' doesn't exist","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateAggregateStatement.java","lineNumber":122,"sourceCode":"    {\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\n        List<AbstractType<?>> argumentTypes =\n            rawArgumentTypes.stream()\n                            .map(t -> t.prepare(keyspaceName, keyspace.types).getType().udfType())\n                            .collect(toList());\n        AbstractType<?> stateType = rawStateType.prepare(keyspaceName, keyspace.types).getType().udfType();\n        List<AbstractType<?>> stateFunctionArguments = Lists.newArrayList(concat(singleton(stateType), argumentTypes));\n\n        UserFunction stateFunction =\n            keyspace.userFunctions\n                    .find(stateFunctionName, stateFunctionArguments)\n                    .orElseThrow(() -> ire(\"State function %s doesn't exist\", stateFunctionString()));\n\n        if (stateFunction.isAggregate())","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateAggregateStatement.java#L104-L140","documentation":"Generic existence guard in schema-altering statements: the target keyspace is absent from the current schema when the DDL transformation is applied, so the statement is rejected rather than implicitly creating the keyspace.","triggerScenarios":"CREATE AGGREGATE <ks>.<name> (or USE'd keyspace) where ks does not exist in ClusterMetadata.schema at apply time.","commonSituations":"Typo in keyspace name; running DDL against a cluster/environment where the keyspace was never created or was dropped; case-sensitivity mismatch (unquoted names lowercased).","solutions":["Create the keyspace first (CREATE KEYSPACE) or fix its name in the statement","Check the case: unquoted identifiers are lowercased; quote 'MyKeyspace' if needed","Verify you are connected to the expected cluster/environment"],"exampleFix":"// before\nCREATE AGGREGATE kyes.agg(int) ...\n// after\nCREATE AGGREGATE keys.agg(int) ...  -- or CREATE KEYSPACE kyes WITH replication = ...; first","handlingStrategy":"validation","validationCode":"Row ks = session.execute(\"SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = ?\", name).one();\nif (ks == null) throw new IllegalStateException(\"Keyspace does not exist: \" + name);","typeGuard":"function keyspaceExists(row) { return row != null && typeof row.keyspace_name === 'string'; }","tryCatchPattern":"try { session.execute(ddl); }\ncatch (InvalidRequestException e) { if (e.getMessage().contains(\"doesn't exist\")) ensureKeyspace(extractKs(e)); else throw e; }","preventionTips":["Verify keyspace existence before running any keyspace-scoped DDL","Keep keyspace names lowercase unless deliberately quoted","Run migrations in environment-aware order (keyspace bootstrap first)"],"tags":["cql","keyspace","ddl","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}