apache/cassandra · error · org.apache.cassandra.cql3.InvalidRequestException
Invalid number of arguments, expecting %d values but got %d
Error message
Invalid number of arguments, expecting %d values but got %d
What it means
Thrown by CQLSSTableWriter.rawAddRow(List<ByteBuffer>) as an InvalidRequestException when the provided value list does not contain exactly one value per bound variable in the INSERT/UPDATE statement. The writer validates the count against boundNames before building QueryOptions, because a missing or extra value cannot be bound to the prepared modification statement.
Source
Thrown at src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java:280
throws InvalidRequestException, IOException
{
return rawAddRow(Arrays.asList(values));
}
/**
* Adds a new row to the writer given already serialized values.
* <p>
* This is a shortcut for {@code rawAddRow(Arrays.asList(values))}.
*
* @param values the row values (corresponding to the bind variables of the
* modification statement used when creating by this writer) as binary.
* @return this writer.
*/
public CQLSSTableWriter rawAddRow(List<ByteBuffer> values)
throws InvalidRequestException, IOException
{
if (values.size() != boundNames.size())
throw new InvalidRequestException(String.format("Invalid number of arguments, expecting %d values but got %d", boundNames.size(), values.size()));
QueryOptions options = QueryOptions.forInternalCalls(null, values);
ClientState state = ClientState.forInternalCalls();
List<ByteBuffer> keys = modificationStatement.buildPartitionKeyNames(options, state);
long now = currentTimeMillis();
// Note that we asks indexes to not validate values (the last 'false' arg below) because that triggers a 'Keyspace.open'
// and that forces a lot of initialization that we don't want.
RowUpdateBuilder builder = new RegularRowUpdateBuilder(modificationStatement.metadata,
ClientState.forInternalCalls(),
options,
modificationStatement.getTimestamp(TimeUnit.MILLISECONDS.toMicros(now), options),
options.getNowInSec((int) TimeUnit.MILLISECONDS.toSeconds(now)),
modificationStatement.getTimeToLive(options),
null);
try
{View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Count the bound variables in your INSERT/UPDATE statement and match the list size exactly
- Pass null (a null element in the list) for optional columns instead of omitting the element
- Regenerate row-building code after any schema or statement change
- Use rawAddRow(String, List) or Map-based addToRow variants that are less positional-error-prone
Example fix
// before writer.rawAddRow(Arrays.asList(key, col1)); // statement binds 3 values // after writer.rawAddRow(Arrays.asList(key, col1, col2)); // null for missing, not omitted
Defensive patterns
Strategy: validation
Validate before calling
List<ByteBuffer> vals = ...; if (vals.size() != expectedBoundCount) throw new IllegalArgumentException("expected " + expectedBoundCount + " values, got " + vals.size()); Type guard
null
Try / catch
try { writer.rawAddRow(values); } catch (InvalidRequestException e) { if (e.getMessage().startsWith("Invalid number of arguments")) { /* fix row arity */ } throw e; } Prevention
- Keep a constant listing bound variables and derive row lists from it
- Pass null elements for skipped columns rather than omitting them
- Re-run a smoke insert after any schema or INSERT statement change
- Prefer rawAddRow(Map) so column-to-value binding is explicit
When it happens
Trigger: rawAddRow(List<ByteBuffer>) or rawAddRow(Object...) is called with fewer or more values than the number of '?' placeholders in the USING/INSERT statement supplied via using().
Common situations: Adding or removing a column in the schema/insert statement but forgetting to update the row data arrays; building rows programmatically where a null column is skipped instead of passed as null; positional confusion after adding a clustering column.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Key <key> in <keyspace>.<table> is invalid in <sstable>: <in
- %s doesn't exists
- %s exists but is not writable
- No ouptut directory specified, you should provide a director
- Missing schema, you should provide the schema for the SSTabl
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/1c0b506131471318.
Report an issue: GitHub.