{"record":{"id":"7fdcdf07cc4b31d2","repo":"apache/cassandra","slug":"invalid-tuple-type-literal-for-s-of-type-s","errorCode":null,"errorMessage":"Invalid tuple type literal for %s of type %s","messagePattern":"Invalid tuple type literal for (.+?) of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Tuples.java","lineNumber":182,"sourceCode":"            if (type == null)\n                return null;\n            types.add(type);\n        }\n        return new TupleType(types);\n    }\n\n    /**\n     * Checks if the tuple with the specified elements can be assigned to the specified column.\n     *\n     * @param receiver the receiving column\n     * @param elements the tuple elements\n     * @throws InvalidRequestException if the tuple cannot be assigned to the specified column.\n     */\n    public static void validateTupleAssignableTo(ColumnSpecification receiver,\n                                                 List<? extends AssignmentTestable> elements)\n    {\n        if (!checkIfTupleType(receiver.type))\n            throw invalidRequest(\"Invalid tuple type literal for %s of type %s\", receiver.name, receiver.type.asCQL3Type());\n\n        TupleType tt = getTupleType(receiver.type);\n        for (int i = 0; i < elements.size(); i++)\n        {\n            if (i >= tt.size())\n            {\n                throw invalidRequest(\"Invalid tuple literal for %s: too many elements. Type %s expects %d but got %d\",\n                                     receiver.name, tt.asCQL3Type(), tt.size(), elements.size());\n            }\n\n            AssignmentTestable value = elements.get(i);\n            ColumnSpecification spec = componentSpecOf(receiver, i);\n            if (!value.testAssignment(receiver.ksName, spec).isAssignable())\n                throw invalidRequest(\"Invalid tuple literal for %s: component %d is not of type %s\",\n                                     receiver.name, i, spec.type.asCQL3Type());\n        }\n    }\n","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Tuples.java#L164-L200","documentation":"validateTupleAssignableTo first checks that the receiver's type is a tuple type at all; if a tuple literal is supplied for a column whose type is not a tuple (after unwrap), this error is thrown. It is the arity/element checks' guard clause, invoked from testTupleAssignment.","triggerScenarios":"Using a tuple literal (a, b, c) for a column of a non-tuple type (e.g. text, list<..>, UDT), either in INSERT/UPDATE values or comparisons during assignment testing.","commonSituations":"Column type changed from tuple to something else; confusing UDTs with tuple syntax (UDTs use {field: value}); driver code emitting tuple literals for json/UDT columns.","solutions":["Match the literal to the column type: use a UDT literal {field: value} for user-defined types, list/set/map literals for collections.","Confirm the column type via DESCRIBE TABLE and correct the statement.","If a tuple was intended, alter the column to the appropriate tuple type first."],"exampleFix":"// before (address is a UDT)\nINSERT INTO t (id, address) VALUES (1, ('Main St', 42));\n// after\nINSERT INTO t (id, address) VALUES (1, {street: 'Main St', num: 42});","handlingStrategy":"type-guard","validationCode":"if (!colType.startsWith(\"tuple<\")) throw new IllegalArgumentException(\"tuple literal requires a tuple column, got \" + colType);","typeGuard":"boolean acceptsTupleLiteral(String columnType) { return columnType != null && columnType.startsWith(\"tuple<\"); }","tryCatchPattern":null,"preventionTips":["Use UDT literal syntax {field: value} for user-defined types, never positional tuples.","Verify column types after migrations before emitting literals."],"tags":["cql","tuple","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-14T16:17:12.679Z"}