{"record":{"id":"e109a8cc3cf517bb","repo":"apache/cassandra","slug":"expected-d-elements-in-value-for-tuple-s-but-go","errorCode":null,"errorMessage":"Expected %d elements in value for tuple %s, but got %d: %s","messagePattern":"Expected (.+?) elements in value for tuple (.+?), but got (.+?): (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Tuples.java","lineNumber":76,"sourceCode":"\n        public Literal(List<Term.Raw> elements)\n        {\n            this.elements = elements;\n        }\n\n        public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException\n        {\n            // The parser cannot differentiate between a tuple with one element and a term between parenthesis.\n            // By consequence, we need to wait until we know the target type to determine which one it is.\n            if (elements.size() == 1 && !checkIfTupleType(receiver.type))\n                return elements.get(0).prepare(keyspace, receiver);\n\n            validateTupleAssignableTo(receiver, elements);\n\n            TupleType tupleType = getTupleType(receiver.type);\n\n            if (elements.size() != tupleType.size())\n                throw invalidRequest(\"Expected %d elements in value for tuple %s, but got %d: %s\",\n                                     tupleType.size(), receiver.name, elements.size(), this);\n\n            List<Term> values = new ArrayList<>(elements.size());\n            boolean allTerminal = true;\n            for (int i = 0; i < elements.size(); i++)\n            {\n                Term value = elements.get(i).prepare(keyspace, componentSpecOf(receiver, i));\n                if (value instanceof Term.NonTerminal)\n                    allTerminal = false;\n\n                values.add(value);\n            }\n\n            MultiElements.DelayedValue value = new MultiElements.DelayedValue(tupleType, values);\n            return allTerminal ? value.bind(FunctionContext.NONE) : value;\n        }\n\n        public TestResult testAssignment(String keyspace, ColumnSpecification receiver)","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Tuples.java#L58-L94","documentation":"Tuples.prepare checks that the number of elements in a tuple literal matches the receiver's TupleType arity. A literal with fewer or more elements than the tuple type declares is rejected with this error stating expected and actual counts.","triggerScenarios":"INSERT/UPDATE binding a tuple literal like (1, 'a') to a column of type tuple<int, text, double> (2 vs 3 elements), including frozen tuple literals and literal tuples in WHERE clauses during prepare.","commonSituations":"Schema altered the tuple arity (ALTER ... tuple type changed) while client literals were not updated; generating literals from variable-length records (CSV/JSON rows); positional destructuring mistakes.","solutions":["Supply exactly tupleType.size() elements, using null for missing positions.","Check the tuple arity via DESCRIBE TABLE and update the application's tuple construction.","If records are variable length, pad/truncate in application code before building the literal."],"exampleFix":"// before (tuple<int, text, double>)\nINSERT INTO t (id, pos) VALUES (1, (1, 'x'));\n// after\nINSERT INTO t (id, pos) VALUES (1, (1, 'x', null));","handlingStrategy":"validation","validationCode":"int arity = /* from system_schema.columns type tuple<...> */ 3;\nif (values.length != arity) throw new IllegalArgumentException(\"expected \" + arity + \" tuple elements, got \" + values.length);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Parse tuple arity from the declared type and assert before composing literals.","Pad with nulls explicitly when source records may be short."],"tags":["cql","tuple","arity"],"backgroundTag":"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"}