Fix error when trying to assign a tuple to target type not being a tuple

patch by Stefan Miklosovic; reviewed by David Capwell for CASSANDRA-20237
This commit is contained in:
Stefan Miklosovic 2025-01-22 13:33:51 +01:00
parent b4bcdfa785
commit 06f0965a08
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
4 changed files with 9 additions and 5 deletions

View File

@ -1,4 +1,5 @@
5.1
* Fix error when trying to assign a tuple to target type not being a tuple (CASSANDRA-20237)
* Fail CREATE TABLE LIKE statement if UDTs in target keyspace do not exist or they have different structure from ones in source keyspace (CASSANDRA-19966)
* Support octet_length and length functions (CASSANDRA-20102)
* Make JsonUtils serialize Instant always with the same format (CASSANDRA-20209)

View File

@ -68,14 +68,14 @@ public final class Tuples
if (elements.size() == 1 && !checkIfTupleType(receiver.type))
return elements.get(0).prepare(keyspace, receiver);
validateTupleAssignableTo(receiver, elements);
TupleType tupleType = getTupleType(receiver.type);
if (elements.size() != tupleType.size())
throw invalidRequest("Expected %d elements in value for tuple %s, but got %d: %s",
tupleType.size(), receiver.name, elements.size(), this);
validateTupleAssignableTo(receiver, elements);
List<Term> values = new ArrayList<>(elements.size());
boolean allTerminal = true;
for (int i = 0; i < elements.size(); i++)

View File

@ -149,7 +149,7 @@ public class TupleTypeTest extends CQLTester
assertInvalidSyntax("INSERT INTO %s (k, t) VALUES (0, ())");
assertInvalidMessage("Expected 3 elements in value for tuple t, but got 4: (2, 'foo', 3.1, 'bar')",
assertInvalidMessage("Invalid tuple literal for t: too many elements. Type frozen<tuple<int, text, double>> expects 3 but got 4",
"INSERT INTO %s (k, t) VALUES (0, (2, 'foo', 3.1, 'bar'))");
createTable("CREATE TABLE %s (k int PRIMARY KEY, t frozen<tuple<int, tuple<int, text, double>>>)");
@ -159,6 +159,9 @@ public class TupleTypeTest extends CQLTester
assertInvalidMessage("Invalid tuple literal for t: component 1 is not of type frozen<tuple<int, text, double>>",
"INSERT INTO %s (k, t) VALUES (0, (1, (1, '1', 1.0, 1)))");
assertInvalidMessage("Invalid tuple type literal for k of type int",
"SELECT * FROM %s WHERE k = ('a', 'b')");
}
@Test

View File

@ -58,7 +58,7 @@ public class SelectMultiColumnRelationTest extends CQLTester
createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c, d))");
assertInvalidSyntax("SELECT * FROM %s WHERE a = 0 AND (b, c) > ()");
assertInvalidMessage("Expected 2 elements in value for tuple (b, c), but got 3: (?, ?, ?)",
assertInvalidMessage("Invalid tuple literal for (b, c): too many elements. Type frozen<tuple<int, int>> expects 2 but got 3",
"SELECT * FROM %s WHERE a = 0 AND (b, c) > (?, ?, ?)", 1, 2, 3);
assertInvalidMessage("Invalid null value for c in tuple (b, c)",
"SELECT * FROM %s WHERE a = 0 AND (b, c) > (?, ?)", 1, null);
@ -72,7 +72,7 @@ public class SelectMultiColumnRelationTest extends CQLTester
// Wrong number of values
assertInvalidMessage("Expected 3 elements in value for tuple (b, c, d), but got 2: (?, ?)",
"SELECT * FROM %s WHERE a=0 AND (b, c, d) IN ((?, ?))", 0, 1);
assertInvalidMessage("Expected 3 elements in value for tuple (b, c, d), but got 5: (?, ?, ?, ?, ?)",
assertInvalidMessage("Invalid tuple literal for (b, c, d): too many elements. Type frozen<tuple<int, int, int>> expects 3 but got 5",
"SELECT * FROM %s WHERE a=0 AND (b, c, d) IN ((?, ?, ?, ?, ?))", 0, 1, 2, 3, 4);
// Missing first clustering column