apache/cassandra · error · InvalidRequestException
Invalid slice selection
Error message
Invalid slice selection: %s of type %s is not a collection
What it means
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.
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
Example fix
// before SELECT scalar_col[0..3] FROM ks.tbl; // after SELECT list_col[0..3] FROM ks.tbl; -- list_col must be a list/set/map
Defensive patterns
Strategy: validation
Validate before calling
// verify column is a collection before slice access
String type = getColumnType(keyspace, table, column);
if (!type.matches("(list|set|map).*")) throw new IllegalArgumentException(column + " is not a collection; cannot use [lo..hi]"); Try / catch
try { session.execute(sliceSelect); } catch (InvalidRequestException e) { if (e.getMessage().contains("is not a collection")) { /* fall back to selecting whole column */ } else throw e; } Prevention
- 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
When it happens
Trigger: SELECT mycol[0..5] or mycol['a'..'z'] where mycol's effective type is not a list/set/map.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- appendAll() can only be called on non-frozen collections
- Invalid element selection
- Cannot create index on
- Cannot create () index on frozen column . Frozen…
- Cannot create () index on . Non-collection columns only…
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/0a90f4abc2d123e3.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/selection/Selectable.java:1566
@Override
public String toString()
{
return String.format("%s[%s..%s]", selected, from == null ? "" : from, to == null ? "" : to);
}
public Selector.Factory newSelectorFactory(TableMetadata cfm, AbstractType<?> expectedType, List<ColumnMetadata> defs, VariableSpecifications boundNames)
{
// Note that a slice gives you the same type as the collection you applied it to, so we can pass expectedType for selected directly
Selector.Factory factory = selected.newSelectorFactory(cfm, expectedType, defs, boundNames);
ColumnSpecification receiver = factory.getColumnSpecification(cfm);
AbstractType<?> type = receiver.type;
if (receiver.isReversedType())
{
type = ((ReversedType<?>) type).baseType;
}
if (!(type instanceof CollectionType))
throw new InvalidRequestException(String.format("Invalid slice selection: %s of type %s is not a collection", selected, type.asCQL3Type()));
ColumnSpecification boundSpec = specForElementOrSlice(selected, receiver, ((CollectionType) type).kind, "Slice");
// If from or to are null, this means the user didn't provide on in the syntax (we had c[x..] or c[..x]).
// The equivalent of doing this when preparing values would be to use UNSET.
Term f = from == null ? Constants.UNSET_VALUE : from.prepare(cfm.keyspace, boundSpec);
Term t = to == null ? Constants.UNSET_VALUE : to.prepare(cfm.keyspace, boundSpec);
f.collectMarkerSpecification(boundNames, cfm);
t.collectMarkerSpecification(boundNames, cfm);
return ElementsSelector.newSliceFactory(toString(), factory, (CollectionType)type, f, t);
}
public AbstractType<?> getExactTypeIfKnown(String keyspace)
{
AbstractType<?> selectedType = selected.getExactTypeIfKnown(keyspace);
if (selectedType == null || !(selectedType instanceof CollectionType))
return null;
View on GitHub (pinned to 88fd0f6a0e)