You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2015/07/18 00:03:56 UTC
cassandra git commit: Fix ALTER TABLE ADD validation for frozen
collections
Repository: cassandra
Updated Branches:
refs/heads/trunk 1b5fa8ce3 -> fa7103ffd
Fix ALTER TABLE ADD validation for frozen collections
patch by Aleksey Yeschenko; reviewed by Tyler Hobbs for CASSANDRA-9816
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/fa7103ff
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/fa7103ff
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/fa7103ff
Branch: refs/heads/trunk
Commit: fa7103ffddd85ab38092c2aa01971d88f5c5ef3f
Parents: 1b5fa8c
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Sat Jul 18 01:04:02 2015 +0300
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Sat Jul 18 01:04:02 2015 +0300
----------------------------------------------------------------------
.../cql3/statements/AlterTableStatement.java | 20 +++++++++++++-------
.../validation/entities/CollectionsTest.java | 9 +++++++++
2 files changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/fa7103ff/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
index a247cdb..ebd3d5b 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -125,14 +125,20 @@ public class AlterTableStatement extends SchemaAlteringStatement
if (cfm.isSuper())
throw new InvalidRequestException("Cannot use non-frozen collections with super column families");
- // If there used to be a collection column with the same name (that has been dropped), we could still have
- // some data using the old type, and so we can't allow adding a collection with the same name unless
- // the types are compatible (see #6276).
+ // If there used to be a non-frozen collection column with the same name (that has been dropped),
+ // we could still have some data using the old type, and so we can't allow adding a collection
+ // with the same name unless the types are compatible (see #6276).
CFMetaData.DroppedColumn dropped = cfm.getDroppedColumns().get(columnName.bytes);
- if (dropped != null && dropped.type instanceof CollectionType && !type.isCompatibleWith(dropped.type))
- throw new InvalidRequestException(String.format("Cannot add a collection with the name %s " +
- "because a collection with the same name and a different type%s has already been used in the past",
- columnName, " (" + dropped.type.asCQL3Type() + ')'));
+ if (dropped != null && dropped.type instanceof CollectionType
+ && dropped.type.isMultiCell() && !type.isCompatibleWith(dropped.type))
+ {
+ String message =
+ String.format("Cannot add a collection with the name %s because a collection with the same name"
+ + " and a different type (%s) has already been used in the past",
+ columnName,
+ dropped.type.asCQL3Type());
+ throw new InvalidRequestException(message);
+ }
}
Integer componentIndex = cfm.isCompound() ? cfm.comparator.size() : null;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/fa7103ff/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
index 72f5ad5..fdd3dfa 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
@@ -585,4 +585,13 @@ public class CollectionsTest extends CQLTester
assertInvalid("alter table %s add v set<int>");
}
+ @Test
+ public void testDropAndReaddDroppedCollection() throws Throwable
+ {
+ createTable("create table %s (k int primary key, v frozen<set<text>>, x int)");
+ execute("insert into %s (k, v) VALUES (0, {'fffffffff'})");
+ flush();
+ execute("alter table %s drop v");
+ execute("alter table %s add v set<int>");
+ }
}