apache/cassandra · error · InvalidRequestException

Invalid operation (%s) for non-numeric and non-text type %s

Error message

Invalid operation (%s) for non-numeric and non-text type %s

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/cql3/Operation.java:342

    {
        private final Term.Raw value;

        public Addition(Term.Raw value)
        {
            this.value = value;
        }

        public Operation prepare(TableMetadata metadata, ColumnMetadata receiver, boolean canReadExistingState) throws InvalidRequestException
        {
            if (!(receiver.type instanceof CollectionType))
            {
                if (receiver.type instanceof TupleType)
                    throw new InvalidRequestException(String.format("Invalid operation (%s) for tuple column %s", toString(receiver), receiver.name));

                if (canReadExistingState)
                {
                    if (!(receiver.type instanceof NumberType<?>) && !(receiver.type instanceof StringType))
                        throw new InvalidRequestException(String.format("Invalid operation (%s) for non-numeric and non-text type %s", toString(receiver), receiver.name));
                }
                else
                {
                    if (!(receiver.type instanceof CounterColumnType))
                        throw new InvalidRequestException(String.format("Invalid operation (%s) for non counter column %s", toString(receiver), receiver.name));
                }
                return new Constants.Adder(receiver, value.prepare(metadata.keyspace, receiver));
            }
            else if (!(receiver.type.isMultiCell()))
                throw new InvalidRequestException(String.format("Invalid operation (%s) for frozen collection column %s", toString(receiver), receiver.name));

            switch (((CollectionType<?>)receiver.type).kind)
            {
                case LIST:
                    return new Lists.Appender(receiver, value.prepare(metadata.keyspace, receiver));
                case SET:
                    return new Sets.Adder(receiver, value.prepare(metadata.keyspace, receiver));
                case MAP:

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Change the target column to a numeric type (int, bigint, counter...) if incrementing is intended
  2. Use string/blob types if concatenation was intended
  3. Replace the operation with a full assignment of the desired new value
  4. Fix application query builders so '+' operations are only emitted for numeric/text columns

Example fix

// before (flag boolean)
UPDATE users SET flag = flag + 1 WHERE id = 1;
// after
UPDATE users SET flag = true WHERE id = 1;
Defensive patterns

Strategy: validation

Validate before calling

AbstractType<?> t = tm.getColumn(col).getType();
if (!(t instanceof NumberType<?>) && !(t instanceof StringType))
    throw new IllegalArgumentException(col + " does not support + operations");

Type guard

boolean supportsAdd(AbstractType<?> t) { return t instanceof NumberType<?> || t instanceof StringType; }

Prevention

When it happens

Trigger: '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).

Common situations: Assuming '+' works like concatenation on any type; trying to increment a uuid/inet/boolean column; ORM-generated increments applied to all columns.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/e666e90bf6f2e643. Report an issue: GitHub.