apache/cassandra · error · InvalidRequestException
Invalid map literal for %s of type %s
Error message
Invalid map literal for %s of type %s
What it means
Thrown during term preparation when a map literal is assigned to a receiver whose type is not a MapType. The literal syntax `{...}` was used for a column/field of some other type, so validation cannot proceed.
Source
Thrown at src/java/org/apache/cassandra/cql3/terms/Maps.java:212
if (k.containsBindMarker() || v.containsBindMarker())
throw new InvalidRequestException(String.format("Invalid map literal for %s: bind variables are not supported inside collection literals", receiver.name));
if (k instanceof Term.NonTerminal || v instanceof Term.NonTerminal)
allTerminal = false;
values.add(k);
values.add(v);
}
MultiElements.DelayedValue value = new MultiElements.DelayedValue((MultiElementType<?>) receiver.type.unwrap(), values);
return allTerminal ? value.bind(QueryOptions.DEFAULT) : value;
}
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
AbstractType<?> type = receiver.type.unwrap();
if (!(type instanceof MapType))
throw new InvalidRequestException(String.format("Invalid map literal for %s of type %s", receiver.name, receiver.type.asCQL3Type()));
ColumnSpecification keySpec = Maps.keySpecOf(receiver);
ColumnSpecification valueSpec = Maps.valueSpecOf(receiver);
for (Pair<Term.Raw, Term.Raw> entry : entries)
{
if (!entry.left.testAssignment(keyspace, keySpec).isAssignable())
throw new InvalidRequestException(String.format("Invalid map literal for %s: key %s is not of type %s", receiver.name, entry.left, keySpec.type.asCQL3Type()));
if (!entry.right.testAssignment(keyspace, valueSpec).isAssignable())
throw new InvalidRequestException(String.format("Invalid map literal for %s: value %s is not of type %s", receiver.name, entry.right, valueSpec.type.asCQL3Type()));
}
}
public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)
{
return testMapAssignment(receiver, entries);
}
@OverrideView on GitHub (pinned to 88fd0f6a0e)
Solutions
- Correct the statement to match the column's declared type (use `[...]` for lists, `{...}` without colons for sets).
- Check the schema with DESCRIBE/SELECT from system_schema.columns and align the query.
- Alter the column type if a map is truly intended (requires compatible type change).
Example fix
// before (c is a set)
"UPDATE t SET c = {'a':1} WHERE k=?"
// after
"UPDATE t SET c = {'a'} WHERE k=?" Defensive patterns
Strategy: validation
Validate before calling
String type = session.execute("SELECT type FROM system_schema.columns WHERE keyspace_name=? AND table_name=? AND column_name=?", ks, tb, col).one().getString("type");
if (!type.startsWith("map<")) throw new IllegalArgumentException(col + " is not a map: " + type); Type guard
boolean isMapColumn(String columnType) { return columnType.startsWith("map<") || columnType.startsWith("frozen<map<"); } Try / catch
try { session.prepare(sql); } catch (InvalidRequestException e) { if (e.getMessage().contains("of type") && e.getMessage().contains("Invalid map literal")) { /* check schema */ } else throw e; } Prevention
- Verify column types in system_schema before writing literal queries
- Regenerate queries after schema migrations
- Use driver object mappers that respect the declared types
When it happens
Trigger: Preparing `SET c = {'a':1}` where column c is a list, set, frozen non-map, or non-collection type; passing a map literal to a UDT or tuple receiver.
Common situations: Schema drift — column type changed from map to set/list after queries were written; copy-paste between columns of different collection types; wrong receiver in a user-defined function argument.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Durations are not allowed as map keys:
- Constraint '%s' can be used only for columns of type %s but
- Function %s requires a map argument, but found argument %s o
- Invalid map literal for %s: key %s is not of type %s
- Invalid map literal for %s: value %s is not of type %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/58a097c0a9ecd3d1.
Report an issue: GitHub.