diff --git a/CHANGES.txt b/CHANGES.txt index d4f9f914d4..a3ec15e279 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.0.14 + * 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 c8cf04561d..f3021cad9f 100644 --- a/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java @@ -44,6 +44,7 @@ import org.apache.cassandra.cql3.QualifiedName; import org.apache.cassandra.db.Keyspace; 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; @@ -201,6 +202,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 0fa945ee10..f1b6b8fb87 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/UserTypesTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/UserTypesTest.java @@ -179,6 +179,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