{"record":{"id":"84c9ca9ff9471e2d","repo":"apache/cassandra","slug":"list-had-incorrect-size-expected-d-but-given-d","errorCode":null,"errorMessage":"List had incorrect size: expected %d but given %d; %s","messagePattern":"List had incorrect size: expected (.+?) but given (.+?); (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/VectorType.java","lineNumber":324,"sourceCode":"            sb.append(elementType.toJSONString(split.get(i), accessor, protocolVersion));\n        }\n        sb.append(']');\n        return sb.toString();\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        if (parsed instanceof String)\n            parsed = JsonUtils.decodeJson((String) parsed);\n\n        if (!(parsed instanceof List))\n            throw new MarshalException(String.format(\n            \"Expected a list, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n\n        List<?> list = (List<?>) parsed;\n        if (list.size() != dimension)\n            throw new MarshalException(String.format(\"List had incorrect size: expected %d but given %d; %s\", dimension, list.size(), list));\n        List<Term> terms = new ArrayList<>(list.size());\n        for (Object element : list)\n        {\n            if (element == null)\n                throw new MarshalException(\"Invalid null element in list\");\n            terms.add(elementType.fromJSONObject(element));\n        }\n\n        return new MultiElements.DelayedValue(this, terms);\n    }\n\n    @Override\n    public boolean equals(Object o)\n    {\n        if (this == o) return true;\n        if (o == null || getClass() != o.getClass()) return false;\n        VectorType<?> that = (VectorType<?>) o;\n        return dimension == that.dimension && Objects.equals(elementType, that.elementType);","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/VectorType.java#L306-L342","documentation":"fromJSONObject verifies that the JSON array's length equals the vector type's declared dimension. A list of any other size is rejected with MarshalException reporting expected vs given size, since vector columns have fixed dimension.","triggerScenarios":"Inserting via JSON with an array whose length differs from the column's declared dimension, e.g. vector<float, 3> given [1.0, 2.0] in a JSON insert path.","commonSituations":"Embedding model dimension changed but the schema (or data pipeline) did not; hand-written JSON payloads with missing/extra elements; ETL jobs truncating arrays.","solutions":["Provide a JSON array with exactly the declared number of elements","ALTER TABLE ... ALTER column TYPE vector<...> to the new dimension if the data legitimately changed size","Validate array length against the schema dimension before inserting"],"exampleFix":"// before\n// vector<float, 3> column\njson = \"[0.1, 0.2]\";\n// after\njson = \"[0.1, 0.2, 0.3]\"; // 3 elements","handlingStrategy":"validation","validationCode":"if (list.size() != dimension)\n    throw new IllegalArgumentException(\"expected \" + dimension + \" elements, got \" + list.size());","typeGuard":null,"tryCatchPattern":"try { term = vt.fromJSONObject(list); } catch (MarshalException e) { /* size mismatch: repair or reject record */ }","preventionTips":["Check list length against schema dimension before insert","Keep embedding model dimension and table schema in sync"],"tags":["cassandra","json","vector-type","dimension-mismatch"],"backgroundTag":"tensor-shape-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"}