{"record":{"id":"0a90f4abc2d123e3","repo":"apache/cassandra","slug":"invalid-slice-selection-s-of-type-s-is-not-a-co","errorCode":null,"errorMessage":"Invalid slice selection: %s of type %s is not a collection","messagePattern":"Invalid slice selection: (.+?) of type (.+?) is not a collection","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/selection/Selectable.java","lineNumber":1566,"sourceCode":"        @Override\n        public String toString()\n        {\n            return String.format(\"%s[%s..%s]\", selected, from == null ? \"\" : from, to == null ? \"\" : to);\n        }\n\n        public Selector.Factory newSelectorFactory(TableMetadata cfm, AbstractType<?> expectedType, List<ColumnMetadata> defs, VariableSpecifications boundNames)\n        {\n            // Note that a slice gives you the same type as the collection you applied it to, so we can pass expectedType for selected directly\n            Selector.Factory factory = selected.newSelectorFactory(cfm, expectedType, defs, boundNames);\n            ColumnSpecification receiver = factory.getColumnSpecification(cfm);\n\n            AbstractType<?> type = receiver.type;\n            if (receiver.isReversedType())\n            {\n                type = ((ReversedType<?>) type).baseType;\n            }\n            if (!(type instanceof CollectionType))\n                throw new InvalidRequestException(String.format(\"Invalid slice selection: %s of type %s is not a collection\", selected, type.asCQL3Type()));\n\n            ColumnSpecification boundSpec = specForElementOrSlice(selected, receiver, ((CollectionType) type).kind, \"Slice\");\n\n            // If from or to are null, this means the user didn't provide on in the syntax (we had c[x..] or c[..x]).\n            // The equivalent of doing this when preparing values would be to use UNSET.\n            Term f = from == null ? Constants.UNSET_VALUE : from.prepare(cfm.keyspace, boundSpec);\n            Term t = to == null ? Constants.UNSET_VALUE : to.prepare(cfm.keyspace, boundSpec);\n            f.collectMarkerSpecification(boundNames, cfm);\n            t.collectMarkerSpecification(boundNames, cfm);\n            return ElementsSelector.newSliceFactory(toString(), factory, (CollectionType)type, f, t);\n        }\n\n        public AbstractType<?> getExactTypeIfKnown(String keyspace)\n        {\n            AbstractType<?> selectedType = selected.getExactTypeIfKnown(keyspace);\n            if (selectedType == null || !(selectedType instanceof CollectionType))\n                return null;\n","sourceCodeStart":1548,"sourceCodeEnd":1584,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/selection/Selectable.java#L1548-L1584","documentation":"Thrown when preparing a slice selection (collection[lo..hi]) if the selected column's type, after unwrapping ReversedType, is not a CollectionType. Slice access over element ranges only exists for collections, so applying it to any other type is rejected.","triggerScenarios":"SELECT mycol[0..5] or mycol['a'..'z'] where mycol's effective type is not a list/set/map.","commonSituations":"Using list-slice syntax on a scalar or UDT column; schema migration changed the column type; confusion between frozen and non-frozen collection slicing support.","solutions":["Confirm the column is a collection (list/set/map) before using [x..y] slice syntax","Select the full column and slice in application code","Cast or re-model the column as a collection if range access is genuinely needed"],"exampleFix":"// before\nSELECT scalar_col[0..3] FROM ks.tbl;\n// after\nSELECT list_col[0..3] FROM ks.tbl;  -- list_col must be a list/set/map","handlingStrategy":"validation","validationCode":"// verify column is a collection before slice access\nString type = getColumnType(keyspace, table, column);\nif (!type.matches(\"(list|set|map).*\")) throw new IllegalArgumentException(column + \" is not a collection; cannot use [lo..hi]\");","typeGuard":null,"tryCatchPattern":"try { session.execute(sliceSelect); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"is not a collection\")) { /* fall back to selecting whole column */ } else throw e; }","preventionTips":["Only apply [x..y] syntax to list/set/map columns","Check schema after migrations that alter column types","Prefer selecting the full column and slicing client-side for non-collections"],"tags":["cql","collections","invalid-argument"],"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-17T15:17:12.973Z"}