apache/cassandra · error · InvalidRequestException
Invalid element selection
Error message
Invalid element selection: %s is of type %s is not a collection
What it means
Thrown when preparing an element selection (collection[key] or collection[idx] in a SELECT) if the type of the selected column, after unwrapping ReversedType, is not a CollectionType. Element access is only defined for lists, sets and maps, so non-collection columns cannot be indexed with [].
Solutions
- Verify the column type with DESC[RIBE] TABLE or system_schema.columns; ensure it is list/set/map
- Remove the [element] accessor and select the whole column instead
- If a reversed type was intended to wrap a collection, ensure the underlying base type is actually a collection
Example fix
// before SELECT plain_text_col['key'] FROM ks.tbl; // after SELECT map_col['key'] FROM ks.tbl; -- map_col must be a map/list/set
Defensive patterns
Strategy: validation
Validate before calling
// verify column is a collection before element access
String type = getColumnType(keyspace, table, column); // from system_schema.columns
if (!type.matches("(list|set|map).*")) throw new IllegalArgumentException(column + " is not a collection; cannot use [element]"); Try / catch
try { session.execute(String.format("SELECT %s[?] FROM %s", col, table), key); } catch (InvalidRequestException e) { if (e.getMessage().contains("is not a collection")) { /* select whole column instead */ } else throw e; } Prevention
- Confirm column types in system_schema.columns before using [] access
- Remember reversed/frozen wrapping does not make a scalar a collection
- Regenerate queries after schema type changes
When it happens
Trigger: SELECT mycol[k] or mycol[idx] where mycol is not a list/set/map (e.g. a text, int, frozen non-collection, or a reversed wrapper around a non-collection).
Common situations: Copy-pasting element-access syntax onto a scalar column; assuming a frozen column is still a collection for element selection; schema changes that changed a column's type after queries were written.
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 slice 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/c194161e34811035.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/selection/Selectable.java:1479
@Override
public String toString()
{
return String.format("%s[%s]", selected, element);
}
public Selector.Factory newSelectorFactory(TableMetadata cfm, AbstractType<?> expectedType, List<ColumnMetadata> defs, VariableSpecifications boundNames)
{
Selector.Factory factory = selected.newSelectorFactory(cfm, null, 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 element selection: %s is of type %s is not a collection", selected, type.asCQL3Type()));
ColumnSpecification boundSpec = specForElementOrSlice(selected, receiver, ((CollectionType) type).kind, "Element");
Term elt = element.prepare(cfm.keyspace, boundSpec);
elt.collectMarkerSpecification(boundNames, cfm);
return ElementsSelector.newElementFactory(toString(), factory, (CollectionType)type, elt);
}
public AbstractType<?> getExactTypeIfKnown(String keyspace)
{
AbstractType<?> selectedType = selected.getExactTypeIfKnown(keyspace);
if (selectedType == null || !(selectedType instanceof CollectionType))
return null;
return ElementsSelector.valueType((CollectionType) selectedType);
}
@OverrideView on GitHub (pinned to 88fd0f6a0e)