From 7d54a62ccc27f89bb6ee55b8f17005cf4c444231 Mon Sep 17 00:00:00 2001 From: Aleksey Yeschenko Date: Thu, 26 Oct 2023 11:13:32 +0100 Subject: [PATCH] Fix schema loading of UDTs inside vectors inside UDTs patch by Aleksey Yeschenko; reviewed by Marcus Eriksson for CASSANDRA-18964 --- CHANGES.txt | 1 + .../org/apache/cassandra/cql3/CQL3Type.java | 6 ++++++ .../validation/operations/CQLVectorTest.java | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 789fade1bd74..d0d38a08c848 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 5.0-alpha2 + * Fix schema loading of UDTs inside vectors inside UDTs (CASSANDRA-18964) * Add cqlsh autocompletion for the vector data type (CASSANDRA-18946) * Fix nodetool tablehistograms output to avoid printing repeated information and ensure at most two arguments (CASSANDRA-18955) * Change the checksum algorithm SAI-related files use from CRC32 to CRC32C (CASSANDRA-18836) diff --git a/src/java/org/apache/cassandra/cql3/CQL3Type.java b/src/java/org/apache/cassandra/cql3/CQL3Type.java index 6b8b97877dd0..304363ad1d05 100644 --- a/src/java/org/apache/cassandra/cql3/CQL3Type.java +++ b/src/java/org/apache/cassandra/cql3/CQL3Type.java @@ -899,6 +899,12 @@ public boolean isVector() return true; } + @Override + public boolean referencesUserType(String name) + { + return element.referencesUserType(name); + } + @Override public boolean supportsFreezing() { diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/CQLVectorTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/CQLVectorTest.java index 42daab6ada7d..3b361bd29c5c 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/operations/CQLVectorTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/CQLVectorTest.java @@ -34,6 +34,7 @@ import org.apache.cassandra.db.marshal.Int32Type; import org.apache.cassandra.db.marshal.VectorType; import org.apache.cassandra.exceptions.InvalidRequestException; +import org.apache.cassandra.schema.SchemaKeyspace; import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.utils.ByteBufferUtil; import org.assertj.core.api.Assertions; @@ -188,6 +189,22 @@ public void invalidNumberOfDimensionsVariableWidth() throws Throwable "INSERT INTO %s (pk, value) VALUES (0, ?)", vector("a", "b", "c")); } + @Test + public void sandwichBetweenUDTs() + { + schemaChange("CREATE TYPE cql_test_keyspace.b (y int);"); + schemaChange("CREATE TYPE cql_test_keyspace.a (z vector, 2>);"); + + // make sure types can be loaded back; see https://issues.apache.org/jira/browse/CASSANDRA-18964 + SchemaKeyspace.fetchNonSystemKeyspaces(); + + createTable("CREATE TABLE %s (pk int primary key, value a)"); + + execute("INSERT INTO %s (pk, value) VALUES (0, {z: [{y:1}, {y:2}]})"); + assertRows(execute("SELECT * FROM %s"), + row(0, userType("z", vector(userType("y", 1), userType("y", 2))))); + } + @Test public void invalidElementTypeFixedWidth() throws Throwable {