apache/cassandra · error · InvalidRequestException
Only column names and monotonic scalar functions are…
Error message
Only column names and monotonic scalar functions are supported in the GROUP BY clause.
What it means
This default implementation of Selector.validateForGroupBy rejects selectors that are not simple column names or supported monotonic scalar functions. GROUP BY in Cassandra requires each selected expression to be either a bare column or an allowed monotonic function of the grouped columns; anything else (aggregations, WRITETIME/TTL, arbitrary functions, non-monotonic expressions) fails validation at prepare time.
Solutions
- Select only bare columns: `SELECT k, v FROM t GROUP BY k;` and compute functions/aggregations client-side.
- If a function is needed, use one of the supported monotonic scalar functions of the grouped columns.
- Remove aggregates (count, sum, etc.) from the select list when GROUP BY is present; use plain selection and aggregate over rows returned.
- Restructure the query — e.g. use a separate aggregation query without GROUP BY or do grouping in the application.
Example fix
// before SELECT count(*), k FROM t GROUP BY k; // after SELECT k, v FROM t GROUP BY k; -- aggregate client-side
Defensive patterns
Strategy: validation
Validate before calling
for (Selector s : selectItems) if (!(s instanceof ColumnIdentifier) && !isAllowedMonotonicScalarFunction(s)) throw new IllegalArgumentException("GROUP BY supports only columns and monotonic scalar functions"); Try / catch
try { session.execute(selectWithGroupBy); } catch (InvalidRequestException e) { if (e.getMessage().contains("GROUP BY clause")) { /* strip functions/aggregates from select list */ } else throw e; } Prevention
- Only select bare columns of the GROUP BY key set.
- Do client-side aggregation instead of aggregate functions with GROUP BY.
- Keep query builders from injecting writetime/ttl/functions into grouped selects.
When it happens
Trigger: `SELECT count(*) FROM t GROUP BY k;` — aggregate in selection with GROUP BY; `SELECT writetime(v) FROM t GROUP BY k;`; arbitrary scalar functions or expressions like a+b in the selection clause alongside GROUP BY.
Common situations: Porting SQL habits (GROUP BY with computed or aggregated select lists) to Cassandra; composing selectors from higher-level query builders that add functions automatically; upgrading code that relied on relaxed validation.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Aggregate function cannot be used for masking table columns
- Altering field types is no longer supported
- Can only select columns by name when defining a…
- Cannot use CREATE TABLE LIKE on a materialized view
- Cannot use CREATE TABLE LIKE on an index table
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/a833a070ab17a03c.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/selection/Selector.java:612
/**
* A selector is terminal if it doesn't require any input for it's output to be computed, i.e. if {@link #getOutput}
* result doesn't depend of {@link #addInput}. This is typically the case of a constant value or functions on constant
* values.
*/
public boolean isTerminal()
{
return false;
}
public void prepare(FunctionContext context) {}
/**
* Checks that this selector is valid for GROUP BY clause.
*/
public void validateForGroupBy()
{
throw invalidRequest("Only column names and monotonic scalar functions are supported in the GROUP BY clause.");
}
protected abstract int serializedSize(int version);
protected abstract void serialize(DataOutputPlus out, int version) throws IOException;
protected static void writeType(DataOutputPlus out, AbstractType<?> type) throws IOException
{
out.writeUTF(type.asCQL3Type().toString());
}
protected static int sizeOf(AbstractType<?> type)
{
return TypeSizes.sizeof(type.asCQL3Type().toString());
}
}
View on GitHub (pinned to 88fd0f6a0e)