{"record":{"id":"a970b335b840d173","repo":"apache/cassandra","slug":"the-length-of-given-vector-value-d-is-not-equal","errorCode":null,"errorMessage":"The length of given vector value '%d' is not equal to the vector size from the type definition '%d'","messagePattern":"The length of given vector value '(.+?)' is not equal to the vector size from the type definition '(.+?)'","errorType":"validation","errorClass":"ParseError","httpStatus":null,"severity":"error","filePath":"pylib/cqlshlib/copyutil.py","lineNumber":2080,"sourceCode":"        def convert_list(val, ct=cql_type):\n            return tuple(convert_mandatory(ct.subtypes[0], v) for v in split(val))\n\n        def convert_set(val, ct=cql_type):\n            return frozenset(convert_mandatory(ct.subtypes[0], v) for v in split(val))\n\n        def convert_map(val, ct=cql_type):\n            \"\"\"\n            See ImmutableDict above for a discussion of why a special object is needed here.\n            \"\"\"\n            split_format_str = '{%s}'\n            sep = ':'\n            return ImmutableDict(frozenset((convert_mandatory(ct.subtypes[0], v[0]), convert(ct.subtypes[1], v[1]))\n                                 for v in [split(split_format_str % vv, sep=sep) for vv in split(val)]))\n\n        def convert_vector(val, ct=cql_type):\n            string_coordinates = split(val)\n            if len(string_coordinates) != ct.vector_size:\n                raise ParseError(\"The length of given vector value '%d' is not equal to the vector size from the type definition '%d'\" % (len(string_coordinates), ct.vector_size))\n            return [convert_mandatory(ct.subtype, v) for v in string_coordinates]\n\n        def convert_user_type(val, ct=cql_type):\n            \"\"\"\n            A user type is a dictionary except that we must convert each key into\n            an attribute, so we are using named tuples. It must also be hashable,\n            so we cannot use dictionaries. Maybe there is a way to instantiate ct\n            directly but I could not work it out.\n            Also note that it is possible that the subfield names in the csv are in the\n            wrong order, so we must sort them according to ct.fieldnames, see CASSANDRA-12959.\n            \"\"\"\n            split_format_str = '{%s}'\n            sep = ':'\n            vals = [v for v in [split(split_format_str % vv, sep=sep) for vv in split(val)]]\n            dict_vals = dict((unprotect(v[0]), v[1]) for v in vals)\n            sorted_converted_vals = [(n, convert(t, dict_vals[n]) if n in dict_vals else self.get_null_val())\n                                     for n, t in zip(ct.fieldnames, ct.subtypes)]\n            ret_type = namedtuple(ct.typename, [v[0] for v in sorted_converted_vals])","sourceCodeStart":2062,"sourceCodeEnd":2098,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/pylib/cqlshlib/copyutil.py#L2062-L2098","documentation":"For a vector column, COPY FROM splits the CSV cell into individual coordinates and requires the count to equal the vector size declared in the schema (ct.vector_size). A different count raises this ParseError. Note the message itself misuses %d for what are string counts, but the semantic is a length mismatch.","triggerScenarios":"COPY FROM a CSV cell for a vector<float, 3> column that contains 2 or 4 elements, e.g. '[1.0, 2.0]' for a 3-dimensional vector, often from a delimiter mismatch producing wrong splits.","commonSituations":"Schema changed the vector dimension after the CSV was exported, wrong bracket/delimiter format causing the splitter to miscount, hand-written rows missing a coordinate.","solutions":["Supply exactly the declared number of coordinates, e.g. [1.0, 2.0, 3.0] for vector<float,3>","Check the table schema (DESCRIBE) to confirm the vector size","Verify quoting/delimiters so the value splits into the right number of elements"],"exampleFix":"// before (vector<float,3>)\n1,\"[1.0,2.0]\"\n// after\n1,\"[1.0,2.0,3.0]\"","handlingStrategy":"validation","validationCode":"vec = parse_bracketed(val)\nif len(vec) != declared_vector_size:\n    raise ValueError(f\"need {declared_vector_size} coords, got {len(vec)}\")","typeGuard":null,"tryCatchPattern":"try:\n    run_copy_from(...)\nexcept ParseError as e:\n    print(f\"Vector length mismatch: {e}\")  # pad/trim coordinates","preventionTips":["Confirm vector dimension with DESCRIBE before generating CSVs","Regenerate CSVs after any schema dimension change","Validate element counts programmatically before import"],"tags":["cqlsh","copy","vector","validation"],"backgroundTag":"shape-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}