{"record":{"id":"7690c0e380815894","repo":"apache/cassandra","slug":"invalid-vector-literal-for-s-value-s-is-not-of","errorCode":null,"errorMessage":"Invalid vector literal for %s: value %s is not of type %s","messagePattern":"Invalid vector literal for (.+?): value (.+?) is not of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Vectors.java","lineNumber":132,"sourceCode":"\n        @Override\n        public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException\n        {\n            AbstractType<?> unwrapped = receiver.type.unwrap();\n\n            if (!unwrapped.isVector())\n                throw new InvalidRequestException(String.format(\"Invalid vector literal for %s of type %s\", receiver.name, receiver.type.asCQL3Type()));\n            VectorType<?> type = (VectorType<?>) unwrapped;\n            if (elements.size() != type.dimension)\n                throw new InvalidRequestException(String.format(\"Invalid vector literal for %s of type %s; expected %d elements, but given %d\", receiver.name, receiver.type.asCQL3Type(), type.dimension, elements.size()));\n\n            ColumnSpecification valueSpec = valueSpecOf(receiver);\n            List<Term> values = new ArrayList<>(elements.size());\n            boolean allTerminal = true;\n            for (Term.Raw rt : elements)\n            {\n                if (!rt.testAssignment(keyspace, valueSpec).isAssignable())\n                    throw new InvalidRequestException(String.format(\"Invalid vector literal for %s: value %s is not of type %s\", receiver.name, rt, valueSpec.type.asCQL3Type()));\n\n                Term t = rt.prepare(keyspace, valueSpec);\n\n                if (t instanceof Term.NonTerminal)\n                    allTerminal = false;\n\n                values.add(t);\n            }\n            MultiElements.DelayedValue value = new MultiElements.DelayedValue(type, values);\n            return allTerminal ? value.bind(FunctionContext.NONE) : value;\n        }\n\n        @Override\n        public String getText()\n        {\n            return Lists.listToString(elements, Term.Raw::getText);\n        }\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Vectors.java#L114-L150","documentation":"Thrown in Vectors.Literal.prepare when an individual element of a vector literal is not assignable to the vector's declared element type. Each element's testAssignment is checked against a receiver specification of the component type.","triggerScenarios":"`[0.1, 'a', 3]` for vector<float, 3> — a string or int element that cannot be coerced to the declared component type; nested collections or UDT literals inside a vector literal.","commonSituations":"Mixing numeric types inconsistently (int literals into float vectors are generally fine, but strings/nulls are not); generated queries embedding non-numeric values from upstream data.","solutions":["Make every element a literal/term of the declared component type (e.g. float for vector<float, N>).","Cast values in the generating application before building the literal.","Sanitize upstream data to remove nulls or non-numeric entries."],"exampleFix":"// before\nINSERT INTO t (embedding) VALUES ([0.1, '0.2', 0.3]); // string element in vector<float,3>\n// after\nINSERT INTO t (embedding) VALUES ([0.1, 0.2, 0.3]);","handlingStrategy":"validation","validationCode":"for (Object el : elements)\n    if (!(el instanceof Float)) throw new IllegalArgumentException(\"Vector element not float: \" + el);","typeGuard":"boolean allFloats(List<Object> xs) { return xs.stream().allMatch(x -> x instanceof Number); }","tryCatchPattern":"try { session.execute(stmt); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"is not of type\")) sanitizeElements(); else throw e; }","preventionTips":["Sanitize upstream data before building vector literals","Cast all elements to the declared component type","Reject nulls/non-numerics before sending"],"tags":["cql","vector","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}