{"record":{"id":"1ecb9520d307d245","repo":"apache/cassandra","slug":"cannot-assign-value-s-to-s-of-type-s-1ecb95","errorCode":null,"errorMessage":"Cannot assign value %s to %s of type %s","messagePattern":"Cannot assign value (.+?) to (.+?) of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/selection/Selectable.java","lineNumber":1317,"sourceCode":"        {\n            if (receiver.type.equals(type))\n                return AssignmentTestable.TestResult.EXACT_MATCH;\n            else if (receiver.type.isValueCompatibleWith(type))\n                return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE;\n            else\n                return AssignmentTestable.TestResult.NOT_ASSIGNABLE;\n        }\n\n        @Override\n        public Factory newSelectorFactory(TableMetadata cfm,\n                                          AbstractType<?> expectedType,\n                                          List<ColumnMetadata> defs,\n                                          VariableSpecifications boundNames)\n        {\n            final ColumnSpecification receiver = new ColumnSpecification(cfm.keyspace, cfm.name, new ColumnIdentifier(toString(), true), type);\n\n            if (!selectable.testAssignment(cfm.keyspace, receiver).isAssignable())\n                throw new InvalidRequestException(String.format(\"Cannot assign value %s to %s of type %s\", this, receiver.name, receiver.type.asCQL3Type()));\n\n            final Factory factory = selectable.newSelectorFactory(cfm, type, defs, boundNames);\n\n            return new ForwardingFactory()\n            {\n                protected Factory delegate()\n                {\n                    return factory;\n                }\n\n                protected AbstractType<?> getReturnType()\n                {\n                    return type;\n                }\n\n                protected String getColumnName()\n                {\n                    return String.format(\"(%s)%s\", typeName, factory.getColumnName());","sourceCodeStart":1299,"sourceCodeEnd":1335,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/selection/Selectable.java#L1299-L1335","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the CQL type produced by the selector and add an explicit cast (e.g. (int), (text)) so it matches the expected receiver type","Simplify the SELECT to select the raw column and do the conversion in application code","Verify against the Cassandra version's Selectable/SelectorFactory type rules; a version upgrade may have changed type checks"],"exampleFix":"// before\nSELECT count(*) AS c FROM ks.tbl;  -- used where a bigint receiver is not assignable\n// after\nSELECT CAST(count(*) AS int) AS c FROM ks.tbl;","handlingStrategy":"validation","validationCode":"// before executing: ensure selector output type matches receiver\nAbstractType<?> selectorType = selectorTypeOf(mySelector);\nif (!receiver.type.testAssignment(selectorType).isAssignable())\n    throw new IllegalArgumentException(\"Selector type \" + selectorType.asCQL3Type() + \" not assignable to \" + receiver.type.asCQL3Type());","typeGuard":null,"tryCatchPattern":"try { session.execute(select); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Cannot assign value\")) { /* fix cast/types in SELECT */ } else throw e; }","preventionTips":["Check each selector's CQL type against the expected output column type","Use explicit CAST() when mixing numeric/text types in selections","Re-validate queries after Cassandra version upgrades"],"tags":["cql","type-mismatch","selection"],"backgroundTag":"type-mismatch","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"}