{"record":{"id":"6ab2548c1985689c","repo":"apache/cassandra","slug":"durations-are-not-allowed-inside-sets-s","errorCode":null,"errorMessage":"Durations are not allowed inside sets: %s","messagePattern":"Durations are not allowed inside sets: (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/selection/Selectable.java","lineNumber":1026,"sourceCode":"                                          VariableSpecifications boundNames)\n        {\n            AbstractType<?> type = getExactTypeIfKnown(cfm.keyspace);\n            if (type == null)\n            {\n                type = expectedType;\n                if (type == null)\n                    throw invalidRequest(\"Cannot infer type for term %s in selection clause (try using a cast to force a type)\",\n                                         this);\n            }\n\n            // The parser treats empty Maps as Sets so if the type is a MapType we know that the Map is empty\n            if (type instanceof MapType)\n                return MapSelector.newFactory(type, Collections.emptyList());\n\n            SetType<?> setType = (SetType<?>) type;\n\n            if (setType.getElementsType() == DurationType.instance)\n                throw invalidRequest(\"Durations are not allowed inside sets: %s\", setType.asCQL3Type());\n\n            List<AbstractType<?>> expectedTypes = new ArrayList<>(selectables.size());\n            for (int i = 0, m = selectables.size(); i < m; i++)\n                expectedTypes.add(setType.getElementsType());\n\n            SelectorFactories factories = createFactoriesAndCollectColumnDefinitions(selectables,\n                                                                                     expectedTypes,\n                                                                                     cfm,\n                                                                                     defs,\n                                                                                     boundNames);\n\n            return SetSelector.newFactory(type, factories);\n        }\n\n        @Override\n        public AbstractType<?> getExactTypeIfKnown(String keyspace)\n        {\n            return Sets.getExactSetTypeIfKnown(selectables, p -> p.getExactTypeIfKnown(keyspace));","sourceCodeStart":1008,"sourceCodeEnd":1044,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/selection/Selectable.java#L1008-L1044","documentation":"A set literal (or inferred set type) used in the selection clause contains duration elements. Cassandra forbids durations inside sets because duration is not orderable, which set elements must be. The request is rejected at prepare time.","triggerScenarios":"`SELECT {1h, 2h} FROM t` — a set literal of durations; an empty or ambiguous literal inferred as set<duration>; passing a term cast to a set type whose element type is duration.","commonSituations":"Trying to store multiple durations in one column via a set; confusing list<duration> (allowed) with set<duration> (forbidden); typos like {5s,10s} where a list was intended.","solutions":["Use a list<duration> (or map with non-key durations) instead of a set, since lists do not require ordering of elements.","Change element type to an orderable duration representation, e.g. set<bigint> of milliseconds.","If durations come from bind markers, cast the term to list<duration> instead of set<duration>."],"exampleFix":"// before\nSELECT {5s, 10s} FROM t;\n// after\nSELECT [5s, 10s] FROM t; -- list<duration>","handlingStrategy":"validation","validationCode":"if (elementType.equals(DurationType.instance) && containerType instanceof SetType) throw new IllegalArgumentException(\"duration not allowed in set; use list<duration>\");","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Durations are not allowed inside sets\")) { /* switch to list/map-value */ } else throw e; }","preventionTips":["Remember the rule: durations allowed in lists and map values, never in sets or map keys.","Validate container element types in code that builds CQL literals.","Model duration collections as list<duration> by convention."],"tags":["cql","duration","set","unsupported-type"],"backgroundTag":"invalid-argument-value","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"}