{"record":{"id":"e666e90bf6f2e643","repo":"apache/cassandra","slug":"invalid-operation-s-for-non-numeric-and-non-tex","errorCode":null,"errorMessage":"Invalid operation (%s) for non-numeric and non-text type %s","messagePattern":"Invalid operation \\((.+?)\\) for non-numeric and non-text type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Operation.java","lineNumber":342,"sourceCode":"    {\n        private final Term.Raw value;\n\n        public Addition(Term.Raw value)\n        {\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            {\n                if (receiver.type instanceof TupleType)\n                    throw new InvalidRequestException(String.format(\"Invalid operation (%s) for tuple column %s\", toString(receiver), receiver.name));\n\n                if (canReadExistingState)\n                {\n                    if (!(receiver.type instanceof NumberType<?>) && !(receiver.type instanceof StringType))\n                        throw new InvalidRequestException(String.format(\"Invalid operation (%s) for non-numeric and non-text type %s\", toString(receiver), receiver.name));\n                }\n                else\n                {\n                    if (!(receiver.type instanceof CounterColumnType))\n                        throw new InvalidRequestException(String.format(\"Invalid operation (%s) for non counter column %s\", toString(receiver), receiver.name));\n                }\n                return new Constants.Adder(receiver, value.prepare(metadata.keyspace, receiver));\n            }\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                    return new Lists.Appender(receiver, value.prepare(metadata.keyspace, receiver));\n                case SET:\n                    return new Sets.Adder(receiver, value.prepare(metadata.keyspace, receiver));\n                case MAP:","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Operation.java#L324-L360","documentation":"Cassandra throws this during preparation when an add/increment operation (col = col + value) targets a column that is neither a numeric type nor a string type, in a context where existing state is readable (regular, non-counter table). Only numbers (with arithmetic semantics) and strings/blobs (concatenation) support the '+' operation.","triggerScenarios":"'UPDATE t SET mycol = mycol + <value>' where mycol is e.g. a boolean, timestamp-incompatible usage, uuid, inet, or any non-number/non-text type in a normal table (canReadExistingState=true).","commonSituations":"Assuming '+' works like concatenation on any type; trying to increment a uuid/inet/boolean column; ORM-generated increments applied to all columns.","solutions":["Change the target column to a numeric type (int, bigint, counter...) if incrementing is intended","Use string/blob types if concatenation was intended","Replace the operation with a full assignment of the desired new value","Fix application query builders so '+' operations are only emitted for numeric/text columns"],"exampleFix":"// before (flag boolean)\nUPDATE users SET flag = flag + 1 WHERE id = 1;\n// after\nUPDATE users SET flag = true WHERE id = 1;","handlingStrategy":"validation","validationCode":"AbstractType<?> t = tm.getColumn(col).getType();\nif (!(t instanceof NumberType<?>) && !(t instanceof StringType))\n    throw new IllegalArgumentException(col + \" does not support + operations\");","typeGuard":"boolean supportsAdd(AbstractType<?> t) { return t instanceof NumberType<?> || t instanceof StringType; }","tryCatchPattern":null,"preventionTips":["Restrict '+' syntax generation to numeric and string columns","Add type-aware validation in ORM/DAO layers before execution","Cover non-numeric update paths with unit tests"],"tags":["cql","cassandra","type-mismatch","operator"],"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"}