{"record":{"id":"ffa6d1e71dc77af6","repo":"apache/cassandra","slug":"invalid-non-frozen-collection-type-s-for-primary","errorCode":null,"errorMessage":"Invalid non-frozen collection type %s for PRIMARY KEY column '%s'","messagePattern":"Invalid non-frozen collection type (.+?) for PRIMARY KEY column '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":306,"sourceCode":"         * Deal with PRIMARY KEY columns\n         */\n\n        HashSet<ColumnIdentifier> primaryKeyColumns = new HashSet<>();\n        concat(partitionKeyColumns, clusteringColumns).forEach(column ->\n        {\n            ColumnProperties properties = columns.get(column);\n            if (null == properties)\n                throw ire(\"Unknown column '%s' referenced in PRIMARY KEY for table '%s'\", column, tableName);\n\n            if (!primaryKeyColumns.add(column))\n                throw ire(\"Duplicate column '%s' in PRIMARY KEY clause for table '%s'\", column, tableName);\n\n            AbstractType<?> type = properties.type;\n            if (type.isMultiCell())\n            {\n                CQL3Type cqlType = properties.cqlType;\n                if (type.isCollection())\n                    throw ire(\"Invalid non-frozen collection type %s for PRIMARY KEY column '%s'\", cqlType, column);\n                else\n                    throw ire(\"Invalid non-frozen user-defined type %s for PRIMARY KEY column '%s'\", cqlType, column);\n            }\n\n            if (type.isCounter())\n                throw ire(\"counter type is not supported for PRIMARY KEY column '%s'\", column);\n\n            if (type.referencesDuration())\n                throw ire(\"duration type is not supported for PRIMARY KEY column '%s'\", column);\n\n            if (staticColumns.contains(column))\n                throw ire(\"Static column '%s' cannot be part of the PRIMARY KEY\", column);\n        });\n\n        List<ColumnProperties> partitionKeyColumnProperties = new ArrayList<>();\n        List<ColumnProperties> clusteringColumnProperties = new ArrayList<>();\n\n        partitionKeyColumns.forEach(column ->","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L288-L324","documentation":"CreateTableStatement.builder validation: a PRIMARY KEY column was declared as a non-frozen collection; multi-cell collections cannot be part of the primary key, so the type must be frozen or removed from the key.","triggerScenarios":"`CREATE TABLE t (k set<int>, PRIMARY KEY (k))` or `PRIMARY KEY (...)` referencing a list/map column without frozen<>.","commonSituations":"Trying to index or key rows by collection values; porting relational designs that used composite keys into CQL collections.","solutions":["Freeze the collection: use `frozen<set<int>>` as the column type","Use a scalar or tuple type for the key column instead","Model the data differently (e.g. denormalize the collection element into the key)"],"exampleFix":"// before\nCREATE TABLE t (k set<int>, v int, PRIMARY KEY (k));\n// after\nCREATE TABLE t (k frozen<set<int>>, v int, PRIMARY KEY (k));","handlingStrategy":"validation","validationCode":"if (keyColumnType.isCollection() && keyColumnType.isMultiCell()) throw new IllegalArgumentException(\"freeze collection before using as PRIMARY KEY column: frozen<...>\");","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"Invalid non-frozen collection type\")) { /* rewrite as frozen<type> */ } else throw e; }","preventionTips":["Never place unfrozen collections in keys","Prefer tuples or scalars for key columns","Add schema review checklist item: all key columns single-cell"],"tags":["cql","collections","primary-key","types"],"backgroundTag":"unsupported-operation","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"}