{"record":{"id":"dbc430383c078a10","repo":"apache/cassandra","slug":"invalid-operation-s-for-non-numeric-type-s","errorCode":null,"errorMessage":"Invalid operation (%s) for non-numeric type %s","messagePattern":"Invalid operation \\((.+?)\\) for non-numeric type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Operation.java","lineNumber":403,"sourceCode":"    }\n\n    public static class Substraction implements RawUpdate\n    {\n        private final Term.Raw value;\n\n        public Substraction(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 (canReadExistingState)\n                {\n                    if (!(receiver.type instanceof NumberType<?>))\n                        throw new InvalidRequestException(String.format(\"Invalid operation (%s) for non-numeric 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.Substracter(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.Discarder(receiver, value.prepare(metadata.keyspace, receiver));\n                case SET:\n                    return new Sets.Discarder(receiver, value.prepare(metadata.keyspace, receiver));\n                case MAP:","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Operation.java#L385-L421","documentation":"An arithmetic operation (e.g. `c = c + 1` via Constants.Adder/Substracter) was applied to a column whose type is neither numeric nor a collection, and the statement requires reading existing state. Cassandra validates the receiver column type at prepare time and rejects non-numeric targets.","triggerScenarios":"`UPDATE t SET some_text_col = some_text_col + 1` or similar + / - operation on a text/boolean/blob/uuid column with canReadExistingState=true.","commonSituations":"Confusing string concatenation with arithmetic; schema drift where a column changed type after queries were written; applying counter-style increments to regular columns.","solutions":["Verify the column type with DESCRIBE TABLE; only numeric types support + / - arithmetic","For counters, ensure the column is of counter type and the table is counter-only","Use string-specific operations instead of arithmetic for text columns","Migrate the column type if arithmetic semantics are actually needed"],"exampleFix":"// before: text column\nUPDATE t SET name = name + 1 WHERE k = 1;\n// after: numeric column\nUPDATE t SET count = count + 1 WHERE k = 1;","handlingStrategy":"validation","validationCode":"// check schema first\nRow r = session.execute(\"SELECT type FROM system_schema.columns WHERE keyspace_name=? AND table_name=? AND column_name=?\", ks, table, col).one();\nboolean numeric = java.util.List.of(\"int\",\"bigint\",\"smallint\",\"tinyint\",\"varint\",\"decimal\",\"double\",\"float\",\"counter\").contains(r.getString(\"type\"));","typeGuard":null,"tryCatchPattern":"try { session.execute(update); } catch (InvalidQueryException e) { if (e.getMessage().contains(\"non-numeric type\")) { /* use non-arithmetic update */ } else throw e; }","preventionTips":["Only use + / - arithmetic on numeric or counter columns","Verify column types after any schema migration","Never use arithmetic as string concatenation in CQL"],"tags":["cql","type-mismatch","arithmetic"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}