{"record":{"id":"105b98ca6f1281d3","repo":"apache/cassandra","slug":"invalid-operation-s-for-set-column-s","errorCode":null,"errorMessage":"Invalid operation (%s) for set column %s","messagePattern":"Invalid operation \\((.+?)\\) for set column (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Operation.java","lineNumber":261,"sourceCode":"            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        }\n\n        protected String toString(ColumnSpecification column)\n        {\n            return String.format(\"%s[%s] = %s\", column.name, selector, value);\n        }\n\n        public boolean isCompatibleWith(RawUpdate other)\n        {\n            // TODO: we could check that the other operation is not setting the same element\n            // too (but since the index/key set may be a bind variables we can't always do it at this point)\n            return !(other instanceof SetValue);","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Operation.java#L243-L279","documentation":"Cassandra throws this during preparation when a keyed collection operation (map put-by-key or list set-by-index pattern) is applied to a set column. Sets have no keys or indices, so SetterByKey/index-style operations are invalid for them; only full assignment or set addition/subtraction is allowed.","triggerScenarios":"Using element/key assignment syntax on a set column, e.g. 'UPDATE t SET myset['k']='v' WHERE ...' or an index-style operation myset[0]=x where myset is set<T>; the prepare() switch on CollectionType.Kind reaches the SET case and rejects it.","commonSituations":"Confusion between set and map column types in the schema; application code templated for maps reused for sets; column type changed from map to set in a migration.","solutions":["Use set add/remove instead of key assignment: SET myset = myset + {'v'} or myset - {'v'}","Verify the column type with DESCRIBE TABLE; if key->value semantics are needed, change the column to map<K,V> (via migration)","Fix code generation/ORM mapping so sets never receive by-key operations"],"exampleFix":"// before (myset is set<text>)\nUPDATE users SET myset['role'] = 'admin' WHERE id = 1;\n// after\nUPDATE users SET myset = myset + {'admin'} WHERE id = 1;","handlingStrategy":"validation","validationCode":"AbstractType<?> t = tm.getColumn(col).getType();\nif (t instanceof CollectionType && ((CollectionType<?>) t).kind == CollectionType.Kind.SET)\n    throw new IllegalArgumentException(\"sets have no keys/indices; use + / - operators\");","typeGuard":"boolean isSet(AbstractType<?> t) { return t instanceof CollectionType && ((CollectionType<?>) t).kind == CollectionType.Kind.SET; }","tryCatchPattern":null,"preventionTips":["Verify column kind (LIST/SET/MAP) before emitting element-level operations","Use distinct repository methods for set vs map updates","Document collection column kinds in the data-access layer"],"tags":["cql","cassandra","set","collection"],"backgroundTag":"unsupported-operation","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"}