{"record":{"id":"8ead54015857ca1b","repo":"apache/cassandra","slug":"invalid-operation-s-for-non-collection-column","errorCode":null,"errorMessage":"Invalid operation (%s) for non collection column %s","messagePattern":"Invalid operation \\((.+?)\\) for non collection column (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Operation.java","lineNumber":250,"sourceCode":"            return false;\n        }\n    }\n\n    public static class SetElement implements RawUpdate\n    {\n        private final Term.Raw selector;\n        private final Term.Raw value;\n\n        public SetElement(Term.Raw selector, Term.Raw value)\n        {\n            this.selector = selector;\n            this.value = value;\n        }\n\n        public Operation prepare(TableMetadata metadata, ColumnMetadata receiver, boolean canReadExistingState) throws InvalidRequestException\n        {\n            if (!(receiver.type instanceof CollectionType))\n                throw new InvalidRequestException(String.format(\"Invalid operation (%s) for non collection column %s\", toString(receiver), receiver.name));\n            else if (!(receiver.type.isMultiCell()))\n                throw new InvalidRequestException(String.format(\"Invalid operation (%s) for frozen collection column %s\", toString(receiver), receiver.name));\n\n            switch (((CollectionType<?>)receiver.type).kind)\n            {\n                case LIST:\n                    Term idx = selector.prepare(metadata.keyspace, Lists.indexSpecOf(receiver));\n                    Term lval = value.prepare(metadata.keyspace, Lists.valueSpecOf(receiver));\n                    return new Lists.SetterByIndex(receiver, idx, lval);\n                case SET:\n                    throw new InvalidRequestException(String.format(\"Invalid operation (%s) for set column %s\", toString(receiver), receiver.name));\n                case MAP:\n                    Term key = selector.prepare(metadata.keyspace, Maps.keySpecOf(receiver));\n                    Term mval = value.prepare(metadata.keyspace, Maps.valueSpecOf(receiver));\n                    return new Maps.SetterByKey(receiver, key, mval);\n            }\n            throw new AssertionError();\n        }","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Operation.java#L232-L268","documentation":"Cassandra throws this during CQL statement preparation when a collection-specific update operation (e.g. list append/set-by-index, map put, set add) is applied to a column whose type is not a collection. Operation.prepare() validates the receiver column type before binding the operation; non-collection columns only support plain constant set operations.","triggerScenarios":"UPDATE/INSERT using collection operations like c[k]=v, c+=..., or c=[...] on a column declared as a non-collection type (text, int, UDT, tuple, etc.); e.g. 'UPDATE t SET mytext[0]='x' WHERE ...' or 'UPDATE t SET mytext = mytext + 'a''.","commonSituations":"Schema drift: the column type was altered from a collection to a scalar (or the query was written for a different table) and old application code still issues collection-style updates; copy-paste between tables with same-named columns of different types.","solutions":["Fix the CQL statement to use a plain assignment (SET col = <value>) matching the column's actual scalar type","DESCRIBE the table and check the column type; adjust the query or use the correct collection column name","If the schema was changed unintentionally, restore the column's collection type (via migration/re-creation with data copy)","Correct application-side query builders so collection operation helpers are only used for list/set/map columns"],"exampleFix":"// before\nUPDATE users SET tags[0] = 'new' WHERE id = 1;  -- tags is text\n// after\nUPDATE users SET tags = 'new' WHERE id = 1;  -- or make tags a list<text> to use index assignment","handlingStrategy":"validation","validationCode":"// Java: check column type before issuing a collection operation\nTableMetadata tm = cluster.getMetadata().getKeyspace(ks).getTable(table);\nAbstractType<?> t = tm.getColumn(col).getType();\nif (!(t instanceof CollectionType)) throw new IllegalArgumentException(col + \" is not a collection; use plain SET col = value\");","typeGuard":"boolean isCollection(AbstractType<?> t) { return t instanceof CollectionType; }","tryCatchPattern":null,"preventionTips":["Run DESCRIBE TABLE / inspect system_schema.columns before generating collection-style updates","Keep client-side schema models in sync with the actual schema after migrations","Avoid copy-pasting update statements between tables with same-named but differently-typed columns"],"tags":["cql","cassandra","schema-validation"],"backgroundTag":"schema-validation-failed","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"}