{"record":{"id":"c19bc9a1e3caac72","repo":"apache/cassandra","slug":"durations-are-not-allowed-inside-sets","errorCode":null,"errorMessage":"Durations are not allowed inside sets: ","messagePattern":"Durations are not allowed inside sets: ","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/CQL3Type.java","lineNumber":868,"sourceCode":"            public CQL3Type prepareInternal(String keyspace, Types udts)\n            {\n                return prepare(keyspace, udts, true);\n            }\n\n            public CQL3Type prepare(String keyspace, Types udts, boolean isInternal) throws InvalidRequestException\n            {\n                assert values != null : \"Got null values type for a collection\";\n\n                if (!frozen && values.supportsFreezing() && !values.frozen)\n                    throwNestedNonFrozenError(values);\n\n                // we represent supercolumns as maps, internally, and we do allow counters in supercolumns. Thus,\n                // for internal type parsing (think schema) we have to make an exception and allow counters as (map) values\n                if (values.isCounter() && !isInternal)\n                    throw new InvalidRequestException(\"Counters are not allowed inside collections: \" + this);\n\n                if (values.isDuration() && kind == Kind.SET)\n                    throw new InvalidRequestException(\"Durations are not allowed inside sets: \" + this);\n\n                if (keys != null)\n                {\n                    if (keys.isCounter())\n                        throw new InvalidRequestException(\"Counters are not allowed inside collections: \" + this);\n                    if (keys.isDuration())\n                        throw new InvalidRequestException(\"Durations are not allowed as map keys: \" + this);\n                    if (!frozen && keys.supportsFreezing() && !keys.frozen)\n                        throwNestedNonFrozenError(keys);\n                }\n\n                AbstractType<?> valueType = values.prepare(keyspace, udts).getType();\n                switch (kind)\n                {\n                    case LIST:\n                        return new Collection(ListType.getInstance(valueType, !frozen));\n                    case SET:\n                        return new Collection(SetType.getInstance(valueType, !frozen));","sourceCodeStart":850,"sourceCodeEnd":886,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/CQL3Type.java#L850-L886","documentation":"Duration values (org.apache.cassandra.db.marshal.DurationType) are forbidden as elements of SET collections. Durations have no natural total ordering (e.g. 1mo vs 30d), which sets require for uniqueness and sorting.","triggerScenarios":"Declaring a column `set<duration>` in CREATE TABLE or ALTER TABLE, or embedding duration inside a non-frozen set type.","commonSituations":"Users attempting to store sets of durations computed from interval data; mistyping `duration` where `time` or a frozen list of durations was intended.","solutions":["Use `list<duration>` or `frozen<list<duration>>` instead of a set — lists allow durations","Store durations as their string/interval representation in a set<text> if ordering does not matter","Use a single duration column if only one value is needed"],"exampleFix":"// before\nCREATE TABLE t (id uuid PRIMARY KEY, offsets set<duration>);\n// after\nCREATE TABLE t (id uuid PRIMARY KEY, offsets frozen<list<duration>>);","handlingStrategy":"validation","validationCode":"boolean usesDurationInSet(String cqlTypeDecl) {\n    return cqlTypeDecl.toLowerCase().replaceAll(\"\\\\s+\",\"\").matches(\"set<.*duration.*\");\n}","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (InvalidQueryException e) { if (e.getMessage().startsWith(\"Durations are not allowed inside sets\")) { /* switch set to list or frozen<list> */ } else throw e; }","preventionTips":["Remember durations lack total ordering — never use them in sets or as map keys","Use list<duration> or encode durations as text for set semantics","Check DurationType restrictions before schema DDL"],"tags":["cql","schema","duration","set"],"backgroundTag":"schema-validation-failed","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"}