{"record":{"id":"d8a531642ab24719","repo":"apache/cassandra","slug":"slice-conditions-s-are-not-supported-on-durat","errorCode":null,"errorMessage":"Slice conditions ( %s ) are not supported on durations","messagePattern":"Slice conditions \\( (.+?) \\) are not supported on durations","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/conditions/ColumnCondition.java","lineNumber":580,"sourceCode":"            checkFalse(operator == Operator.CONTAINS_KEY && !(receiver.type instanceof MapType),\n                       \"Cannot use CONTAINS KEY on non-map column %s\", receiver.name);\n            checkFalse(operator == Operator.CONTAINS && !(receiver.type.isCollection()),\n                       \"Cannot use CONTAINS on non-collection column %s\", receiver.name);\n\n            if (operator == Operator.CONTAINS || operator == Operator.CONTAINS_KEY)\n                receiver = ((CollectionType<?>) receiver.type).makeCollectionReceiver(receiver, operator == Operator.CONTAINS_KEY);\n\n            return values.prepare(keyspace, receiver);\n        }\n\n        private void validateOperationOnDurations(AbstractType<?> type)\n        {\n            if (type.referencesDuration() && operator.isSlice() && operator != Operator.NEQ)\n            {\n                checkFalse(type.isCollection(), \"Slice conditions are not supported on collections containing durations\");\n                checkFalse(type.isTuple(), \"Slice conditions are not supported on tuples containing durations\");\n                checkFalse(type.isUDT(), \"Slice conditions are not supported on UDTs containing durations\");\n                throw invalidRequest(\"Slice conditions ( %s ) are not supported on durations\", operator);\n            }\n        }\n\n        /**\n         * Checks if this raw condition contains bind markers.\n         * @return {@code true} if this raw condition contains bind markers, {@code false} otherwise.\n         */\n        public boolean containsBindMarkers()\n        {\n            return rawExpressions.containsBindMarkers() || values.containsBindMarkers();\n        }\n\n        @VisibleForTesting\n        public String toCQLString()\n        {\n            return operator.buildCQLString(rawExpressions, values);\n        }\n","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/conditions/ColumnCondition.java#L562-L598","documentation":"Cassandra refuses slice comparisons (<, <=, >, >=, CONTAINS-style ranges) against duration values or collections/tuples/UDTs containing durations, because durations have no total ordering (e.g. 1 day vs 24 hours are unequal but incomparable for slicing). The guard in ColumnCondition.Raw throws this when an Operator.isSlice() (and not NEQ) is applied to a duration-referencing type in a condition (IF clause).","triggerScenarios":"A LWT condition like `IF d > 5h`, `IF c[0] <= 1us`, or any slice operator on a duration column, frozen collection containing durations, tuple containing durations, or UDT containing durations.","commonSituations":"Developers trying `IF my_duration < 2h` in a conditional UPDATE/INSERT/DELETE, or slice conditions on nested duration-bearing collections; often after converting a counter/timedelta-style field to Cassandra's duration type.","solutions":["Replace the slice condition with an equality or inequality that is allowed (only = and != are supported on durations)","Store the duration as a numeric value (e.g. milliseconds bigint) if range comparisons are needed","Check the column type with DESC TABLE and confirm whether durations are nested inside a collection/tuple/UDT; move duration out of the nested type","Perform the comparison client-side: read the row, compare in application code, then conditionally write"],"exampleFix":"// before\nUPDATE t SET v = 1 WHERE k = 1 IF dur < 5h;\n// after\nUPDATE t SET v = 1 WHERE k = 1 IF dur = 5h;\n-- or store comparable numeric: UPDATE t SET v = 1 WHERE k = 1 IF dur_ms < 18000000;","handlingStrategy":"validation","validationCode":"// client-side: only = / != allowed on duration columns\nconst SLICE_OPS = ['<', '<=', '>', '>='];\nif (SLICE_OPS.includes(op) && columnType === 'duration') throw new Error('Use = or != for duration conditions');","typeGuard":"function isSliceOp(op) { return ['<','<=','>','>='].includes(op); }","tryCatchPattern":null,"preventionTips":["Never use range operators on duration columns","Store durations as bigint millis when range filtering is required","Keep durations out of frozen collections/tuples/UDTs that need slice conditions"],"tags":["cql","duration","lightweight-transactions","conditions"],"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"}