apache/cassandra · error · InvalidRequestException

Cannot assign value to of type

Error message

Cannot assign value %s to %s of type %s

What it means

Thrown during SELECT statement validation when a raw selector (e.g. a function or Writetime/TTL selector) is checked for assignment compatibility with its expected output type via testAssignment, and the check reports not-assignable. It means the value produced by the selector cannot legally be assigned to a receiver of the declared type, so Cassandra refuses to build the selector factory.

Solutions

  1. Check the CQL type produced by the selector and add an explicit cast (e.g. (int), (text)) so it matches the expected receiver type
  2. Simplify the SELECT to select the raw column and do the conversion in application code
  3. Verify against the Cassandra version's Selectable/SelectorFactory type rules; a version upgrade may have changed type checks

Example fix

// before
SELECT count(*) AS c FROM ks.tbl;  -- used where a bigint receiver is not assignable
// after
SELECT CAST(count(*) AS int) AS c FROM ks.tbl;
Defensive patterns

Strategy: validation

Validate before calling

// before executing: ensure selector output type matches receiver
AbstractType<?> selectorType = selectorTypeOf(mySelector);
if (!receiver.type.testAssignment(selectorType).isAssignable())
    throw new IllegalArgumentException("Selector type " + selectorType.asCQL3Type() + " not assignable to " + receiver.type.asCQL3Type());

Try / catch

try { session.execute(select); } catch (InvalidRequestException e) { if (e.getMessage().startsWith("Cannot assign value")) { /* fix cast/types in SELECT */ } else throw e; }

Prevention

When it happens

Trigger: Issuing a SELECT whose selector's declared output type conflicts with the receiver type created for the result column, e.g. using a nested selector/function whose return type does not satisfy testAssignment against the receiver type computed from the selection.

Common situations: Typo'd or wrong cast/function in a SELECT clause; upgrading code across Cassandra versions where a selector's result type changed; combining selections (e.g. writetime, ttl, functions) on columns whose types the author assumed compatible.

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/1ecb9520d307d245. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/selection/Selectable.java:1317

        {
            if (receiver.type.equals(type))
                return AssignmentTestable.TestResult.EXACT_MATCH;
            else if (receiver.type.isValueCompatibleWith(type))
                return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE;
            else
                return AssignmentTestable.TestResult.NOT_ASSIGNABLE;
        }

        @Override
        public Factory newSelectorFactory(TableMetadata cfm,
                                          AbstractType<?> expectedType,
                                          List<ColumnMetadata> defs,
                                          VariableSpecifications boundNames)
        {
            final ColumnSpecification receiver = new ColumnSpecification(cfm.keyspace, cfm.name, new ColumnIdentifier(toString(), true), type);

            if (!selectable.testAssignment(cfm.keyspace, receiver).isAssignable())
                throw new InvalidRequestException(String.format("Cannot assign value %s to %s of type %s", this, receiver.name, receiver.type.asCQL3Type()));

            final Factory factory = selectable.newSelectorFactory(cfm, type, defs, boundNames);

            return new ForwardingFactory()
            {
                protected Factory delegate()
                {
                    return factory;
                }

                protected AbstractType<?> getReturnType()
                {
                    return type;
                }

                protected String getColumnName()
                {
                    return String.format("(%s)%s", typeName, factory.getColumnName());

View on GitHub (pinned to 88fd0f6a0e)