This is an automated email from the ASF dual-hosted git repository.

smiklosovic pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 06f0965a084 Fix error when trying to assign a tuple to target type not 
being a tuple
06f0965a084 is described below

commit 06f0965a0840dd8bfa93c532b7cf30a3efb0d2b0
Author: Stefan Miklosovic <[email protected]>
AuthorDate: Wed Jan 22 13:33:51 2025 +0100

    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
---
 CHANGES.txt                                                          | 1 +
 src/java/org/apache/cassandra/cql3/terms/Tuples.java                 | 4 ++--
 .../org/apache/cassandra/cql3/validation/entities/TupleTypeTest.java | 5 ++++-
 .../cql3/validation/operations/SelectMultiColumnRelationTest.java    | 4 ++--
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index b9ae2539227..a301dc9bafe 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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)
diff --git a/src/java/org/apache/cassandra/cql3/terms/Tuples.java 
b/src/java/org/apache/cassandra/cql3/terms/Tuples.java
index 6825a16b985..f9ba523567b 100644
--- a/src/java/org/apache/cassandra/cql3/terms/Tuples.java
+++ b/src/java/org/apache/cassandra/cql3/terms/Tuples.java
@@ -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++)
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/entities/TupleTypeTest.java 
b/test/unit/org/apache/cassandra/cql3/validation/entities/TupleTypeTest.java
index 452bb0bc367..90c9778df41 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/TupleTypeTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/TupleTypeTest.java
@@ -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
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
 
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
index 1029196754a..2fe3cffa7f8 100644
--- 
a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
@@ -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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to