diff --git a/CHANGES.txt b/CHANGES.txt index 57b6aa3559..4015caa7da 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,7 @@ * Add java.base/java.lang.reflect among opens for jvm11-client.options (CASSANDRA-19780) Merged from 4.1: Merged from 4.0: + * Emit error when altering a table with non-frozen UDTs with nested non-frozen collections the same way as done upon table creation (CASSANDRA-19925) * Safer handling of out-of-range tokens (CASSANDRA-13704) * Fix memory leak in BTree.FastBuilder (CASSANDRA-19785) * Fix millisecond and microsecond precision for commit log replay (CASSANDRA-19448) diff --git a/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java index fc0b4cffe6..5f37acf09b 100644 --- a/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java @@ -48,6 +48,7 @@ import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.db.guardrails.Guardrails; import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.UserType; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.gms.ApplicationState; import org.apache.cassandra.gms.Gossiper; @@ -314,6 +315,16 @@ public abstract class AlterTableStatement extends AlterSchemaStatement if (isStatic && table.clusteringColumns().isEmpty()) throw ire("Static columns are only useful (and thus allowed) if the table has at least one clustering column"); + // check for nested non-frozen UDTs or collections in a non-frozen UDT + if (type.isUDT() && type.isMultiCell()) + { + for (AbstractType fieldType : ((UserType) type).fieldTypes()) + { + if (fieldType.isMultiCell()) + throw ire("Non-frozen UDTs with nested non-frozen collections are not supported for column " + column.name); + } + } + ColumnMetadata droppedColumn = table.getDroppedColumn(name.bytes); if (null != droppedColumn) { diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/UserTypesTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/UserTypesTest.java index 9ad6aeb047..7a1d73ea37 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/UserTypesTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/UserTypesTest.java @@ -183,6 +183,11 @@ public class UserTypesTest extends CQLTester String myType2 = KEYSPACE + '.' + typename2; assertInvalidMessage("Non-frozen UDTs with nested non-frozen collections are not supported", "CREATE TABLE " + KEYSPACE + ".wrong (k int PRIMARY KEY, v " + myType2 + ")"); + + String userType = createType("CREATE TYPE %s (userids SET)"); + createTable("CREATE TABLE %s (id int PRIMARY KEY)"); + assertInvalidMessage("Non-frozen UDTs with nested non-frozen collections are not supported for column my_type", + "alter TABLE %s add my_type " + userType); } @Test