From 65a3d36eb9def5eb34bdb1fde1c452d365d45be8 Mon Sep 17 00:00:00 2001 From: Stefan Miklosovic Date: Thu, 17 Aug 2023 15:19:28 +0200 Subject: [PATCH] Add more tests for CASSANDRA-16905 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit patch by Stefan Miklosovic; reviewed by Andres de la Peña for CASSANDRA-18760 --- .../cql3/validation/operations/AlterTest.java | 64 ++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java index d1f5206ff8..b3d2b747b1 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java @@ -35,6 +35,41 @@ import static org.junit.Assert.assertEquals; public class AlterTest extends CQLTester { + @Test + public void testNonFrozenCollectionsAreIncompatibleWithBlob() throws Throwable + { + String[] collectionTypes = new String[] {"map", "set", "list"}; + + for (String type : collectionTypes) + { + createTable("CREATE TABLE %s (a int, b " + type + ", PRIMARY KEY (a));"); + alterTable("ALTER TABLE %s DROP b;"); + assertInvalidMessage("Cannot re-add previously dropped column 'b' of type blob, incompatible with previous type " + type, + "ALTER TABLE %s ADD b blob;"); + } + + for (String type : collectionTypes) + { + createTable("CREATE TABLE %s (a int, b blob, PRIMARY KEY (a));"); + alterTable("ALTER TABLE %s DROP b;"); + assertInvalidMessage("Cannot re-add previously dropped column 'b' of type " + type + ", incompatible with previous type blob", + "ALTER TABLE %s ADD b " + type + ';'); + } + } + + @Test + public void testFrozenCollectionsAreCompatibleWithBlob() + { + String[] collectionTypes = new String[] {"frozen>", "frozen>", "frozen>"}; + + for (String type : collectionTypes) + { + createTable("CREATE TABLE %s (a int, b " + type + ", PRIMARY KEY (a));"); + alterTable("ALTER TABLE %s DROP b;"); + alterTable("ALTER TABLE %s ADD b blob;"); + } + } + @Test public void testAddList() throws Throwable { @@ -338,6 +373,27 @@ public class AlterTest extends CQLTester execute("ALTER TABLE %s RENAME c1 TO \"\""); } + @Test + public void testInvalidDroppingAndAddingOfCollections() throws Throwable + { + for (String[] typePair : new String[][] + { + new String[] {"list", "list"}, + new String[] {"set", "set"}, + new String[] {"map", "map"}, + new String[] {"list", "frozen>"}, + new String[] {"set", "frozen>"}, + new String[] {"map", "frozen>"}, + }) + { + createTable("create table %s (k int, c int, v " + typePair[0] + ", PRIMARY KEY (k, c))"); + execute("alter table %s drop v"); + assertInvalidMessage("Cannot re-add previously dropped column 'v' of type " + + typePair[1] + ", incompatible with previous type " + typePair[0], + "alter table %s add v " + typePair[1]); + } + } + @Test(expected = InvalidRequestException.class) public void testDropFixedAddVariable() throws Throwable { @@ -346,14 +402,6 @@ public class AlterTest extends CQLTester execute("alter table %s add v varint"); } - @Test(expected = InvalidRequestException.class) - public void testDropFixedCollectionAddVariableCollection() throws Throwable - { - createTable("create table %s (k int, c int, v list, PRIMARY KEY (k, c))"); - execute("alter table %s drop v"); - execute("alter table %s add v list"); - } - @Test(expected = InvalidRequestException.class) public void testDropSimpleAddComplex() throws Throwable {