{"record":{"id":"58a097c0a9ecd3d1","repo":"apache/cassandra","slug":"invalid-map-literal-for-s-of-type-s","errorCode":null,"errorMessage":"Invalid map literal for %s of type %s","messagePattern":"Invalid map literal for (.+?) of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Maps.java","lineNumber":212,"sourceCode":"                if (k.containsBindMarker() || v.containsBindMarker())\n                    throw new InvalidRequestException(String.format(\"Invalid map literal for %s: bind variables are not supported inside collection literals\", receiver.name));\n\n                if (k instanceof Term.NonTerminal || v instanceof Term.NonTerminal)\n                    allTerminal = false;\n\n                values.add(k);\n                values.add(v);\n            }\n            MultiElements.DelayedValue value = new MultiElements.DelayedValue((MultiElementType<?>) receiver.type.unwrap(), values);\n            return allTerminal ? value.bind(QueryOptions.DEFAULT) : value;\n        }\n\n        private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException\n        {\n            AbstractType<?> type = receiver.type.unwrap();\n\n            if (!(type instanceof MapType))\n                throw new InvalidRequestException(String.format(\"Invalid map literal for %s of type %s\", receiver.name, receiver.type.asCQL3Type()));\n\n            ColumnSpecification keySpec = Maps.keySpecOf(receiver);\n            ColumnSpecification valueSpec = Maps.valueSpecOf(receiver);\n            for (Pair<Term.Raw, Term.Raw> entry : entries)\n            {\n                if (!entry.left.testAssignment(keyspace, keySpec).isAssignable())\n                    throw new InvalidRequestException(String.format(\"Invalid map literal for %s: key %s is not of type %s\", receiver.name, entry.left, keySpec.type.asCQL3Type()));\n                if (!entry.right.testAssignment(keyspace, valueSpec).isAssignable())\n                    throw new InvalidRequestException(String.format(\"Invalid map literal for %s: value %s is not of type %s\", receiver.name, entry.right, valueSpec.type.asCQL3Type()));\n            }\n        }\n\n        public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)\n        {\n            return testMapAssignment(receiver, entries);\n        }\n\n        @Override","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Maps.java#L194-L230","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before (c is a set)\n\"UPDATE t SET c = {'a':1} WHERE k=?\"\n// after\n\"UPDATE t SET c = {'a'} WHERE k=?\"","handlingStrategy":"validation","validationCode":"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\");\nif (!type.startsWith(\"map<\")) throw new IllegalArgumentException(col + \" is not a map: \" + type);","typeGuard":"boolean isMapColumn(String columnType) { return columnType.startsWith(\"map<\") || columnType.startsWith(\"frozen<map<\"); }","tryCatchPattern":"try { session.prepare(sql); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"of type\") && e.getMessage().contains(\"Invalid map literal\")) { /* check schema */ } else throw e; }","preventionTips":["Verify column types in system_schema before writing literal queries","Regenerate queries after schema migrations","Use driver object mappers that respect the declared types"],"tags":["cql","map","type-mismatch","schema"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}