{"record":{"id":"3feaa9cc6af17f97","repo":"apache/cassandra","slug":"required-d-elements-but-saw-d","errorCode":null,"errorMessage":"Required %d elements, but saw %d","messagePattern":"Required (.+?) elements, but saw (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/VectorType.java","lineNumber":366,"sourceCode":"        return Objects.hash(elementType, dimension);\n    }\n\n    @Override\n    public String toString()\n    {\n        return toString(false);\n    }\n\n    @Override\n    public String toString(boolean ignoreFreezing)\n    {\n        return getClass().getName() + TypeParser.stringifyVectorParameters(elementType, ignoreFreezing, dimension);\n    }\n\n    private void check(List<?> values)\n    {\n        if (values.size() != dimension)\n            throw new MarshalException(String.format(\"Required %d elements, but saw %d\", dimension, values.size()));\n\n        // This code base always works with a list that is RandomAccess, so can use .get to avoid allocation\n        for (int i = 0; i < dimension; i++)\n        {\n            Object value = values.get(i);\n            if (value == null || (value instanceof ByteBuffer && elementSerializer.isNull((ByteBuffer) value)))\n                throw new MarshalException(String.format(\"Element at index %d is null (expected type %s); given %s\", i, elementType.asCQL3Type(), values));\n        }\n    }\n\n    private <V> void checkConsumedFully(V buffer, ValueAccessor<V> accessor, int offset)\n    {\n        int remaining = accessor.sizeFromOffset(buffer, offset);\n        if (remaining > 0)\n            throw new MarshalException(\"Unexpected \" + remaining + \" extraneous bytes after \" + asCQL3Type() + \" value\");\n    }\n    \n    private static void rejectNullOrEmptyValue()","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/VectorType.java#L348-L384","documentation":"The private check(List<?>) helper validates that a decomposed element list has exactly as many entries as the vector's dimension, throwing MarshalException otherwise. It guards internal composition paths (e.g. MultiElements.DelayedValue) that assemble vector values from term lists.","triggerScenarios":"Executing an INSERT/UPDATE with a vector literal or bound terms whose element count differs from the declared dimension, e.g. [1, 2, 3] against vector<int, 2>.","commonSituations":"Hand-written CQL vector literals with the wrong element count; application code assembling bind-marker lists of the wrong size; schema drift between application and table.","solutions":["Supply exactly `dimension` elements in the vector literal or bound list","Check the column's dimension via the schema (system_schema.columns / DESCRIBE) before building values","If the required size legitimately changed, ALTER the column type"],"exampleFix":"// before\n// column vector<int, 3>\nINSERT INTO t (v) VALUES ([1, 2]);\n// after\nINSERT INTO t (v) VALUES ([1, 2, 3]);","handlingStrategy":"validation","validationCode":"if (values.size() != dimension)\n    throw new IllegalArgumentException(\"vector requires \" + dimension + \" elements, got \" + values.size());","typeGuard":null,"tryCatchPattern":"try { /* execute statement with vector literal */ } catch (MarshalException e) { /* fix literal size and retry */ }","preventionTips":["Read the column dimension from system_schema before composing literals","Use driver metadata to size vector bind lists"],"tags":["cassandra","vector-type","dimension-mismatch","cql"],"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"}