Emit error when altering a table with non-frozen UDTs with nested non-frozen collections the same way as done upon table creation

patch by Stefan Miklosovic; reviewed by Maxim Muzafarov for CASSANDRA-19925
This commit is contained in:
Stefan Miklosovic 2024-09-16 15:00:37 +02:00
parent 7bf6734957
commit 39b1c2df89
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
3 changed files with 17 additions and 0 deletions

View File

@ -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)

View File

@ -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)
{

View File

@ -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<UUID>)");
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