cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [3/3] git commit: Merge branch 'cassandra-2.0' into cassandra-2.1.0
Date Mon, 11 Aug 2014 16:23:56 GMT
Merge branch 'cassandra-2.0' into cassandra-2.1.0

Conflicts:
	CHANGES.txt
	src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ce96a2a1
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ce96a2a1
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ce96a2a1

Branch: refs/heads/cassandra-2.1.0
Commit: ce96a2a120508ba0a31cc35e44905eae808f4be3
Parents: 4c387e4 bd0bb6d
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Mon Aug 11 18:23:43 2014 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Mon Aug 11 18:23:43 2014 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 +
 .../cql3/statements/AlterTableStatement.java    | 23 +++++-
 .../apache/cassandra/cql3/AlterTableTest.java   | 86 ++++++++++++++++++++
 3 files changed, 110 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce96a2a1/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 910feb4,cd51e04..64b4d65
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,11 -1,7 +1,14 @@@
 -2.0.10
 +2.1.0-rc6
 + * Include stress yaml example in release and deb (CASSANDRA-7717)
 + * workaround for netty issue causing corrupted data off the wire (CASSANDRA-7695)
 + * cqlsh DESC CLUSTER fails retrieving ring information (CASSANDRA-7687)
 + * Fix binding null values inside UDT (CASSANDRA-7685)
 + * Fix UDT field selection with empty fields (CASSANDRA-7670)
 + * Bogus deserialization of static cells from sstable (CASSANDRA-7684)
 +Merged from 2.0:
+  * Better error message when adding a collection with the same name
+    than a previously dropped one (CASSANDRA-6276)
+  * Fix validation when adding static columns (CASSANDRA-7730)
   * (Thrift) fix range deletion of supercolumns (CASSANDRA-7733)
   * Fix potential AssertionError in RangeTombstoneList (CASSANDRA-7700)
   * Validate arguments of blobAs* functions (CASSANDRA-7707)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce96a2a1/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
index 273ee11,136c430..be28943
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@@ -85,16 -86,23 +85,23 @@@ public class AlterTableStatement extend
          switch (oType)
          {
              case ADD:
 -                if (cfDef.isCompact)
 +                if (cfm.comparator.isDense())
                      throw new InvalidRequestException("Cannot add new column to a COMPACT
STORAGE table");
-                 if (isStatic && !cfm.comparator.isCompound())
-                     throw new InvalidRequestException("Static columns are not allowed in
COMPACT STORAGE tables");
+ 
+                 if (isStatic)
+                 {
 -                    if (!cfDef.isComposite)
++                    if (!cfm.comparator.isCompound())
+                         throw new InvalidRequestException("Static columns are not allowed
in COMPACT STORAGE tables");
 -                    if (cfDef.clusteringColumns().isEmpty())
++                    if (cfm.clusteringColumns().isEmpty())
+                         throw new InvalidRequestException("Static columns are only useful
(and thus allowed) if the table has at least one clustering column");
+                 }
+ 
 -                if (name != null)
 +                if (def != null)
                  {
 -                    switch (name.kind)
 +                    switch (def.kind)
                      {
 -                        case KEY_ALIAS:
 -                        case COLUMN_ALIAS:
 +                        case PARTITION_KEY:
 +                        case CLUSTERING_COLUMN:
                              throw new InvalidRequestException(String.format("Invalid column
name %s because it conflicts with a PRIMARY KEY part", columnName));
                          default:
                              throw new InvalidRequestException(String.format("Invalid column
name %s because it conflicts with an existing column", columnName));
@@@ -104,18 -112,39 +111,30 @@@
                  AbstractType<?> type = validator.getType();
                  if (type instanceof CollectionType)
                  {
 -                    if (!cfDef.isComposite)
 +                    if (!cfm.comparator.supportCollections())
                          throw new InvalidRequestException("Cannot use collection types with
non-composite PRIMARY KEY");
 -                    if (cfDef.cfm.isSuper())
 +                    if (cfm.isSuper())
                          throw new InvalidRequestException("Cannot use collection types with
Super column family");
  
 -                    Map<ByteBuffer, CollectionType> collections = cfDef.hasCollections
 -                                                                ? new HashMap<ByteBuffer,
CollectionType>(cfDef.getCollectionType().defined)
 -                                                                : new HashMap<ByteBuffer,
CollectionType>();
+ 
+                     // If there used to be a collection column with the same name (that
has been dropped), it will
+                     // still be appear in the ColumnToCollectionType because or reasons
explained on #6276. The same
+                     // reason mean that we can't allow adding a new collection with that
name (see the ticket for details).
 -                    CollectionType previous = collections.get(columnName.key);
 -                    if (previous != null && !type.isCompatibleWith(previous))
 -                        throw new InvalidRequestException(String.format("Cannot add a collection
with the name %s " +
 -                                    "because a collection with the same name and a different
type has already been used in the past", columnName));
++                    if (cfm.comparator.hasCollections())
++                    {
++                        CollectionType previous = cfm.comparator.collectionType() == null
? null : cfm.comparator.collectionType().defined.get(columnName.bytes);
++                        if (previous != null && !type.isCompatibleWith(previous))
++                            throw new InvalidRequestException(String.format("Cannot add
a collection with the name %s " +
++                                        "because a collection with the same name and a different
type has already been used in the past", columnName));
++                    }
+ 
 -                    collections.put(columnName.key, (CollectionType)type);
 -                    ColumnToCollectionType newColType = ColumnToCollectionType.getInstance(collections);
 -                    List<AbstractType<?>> ctypes = new ArrayList<AbstractType<?>>(((CompositeType)cfm.comparator).types);
 -                    if (cfDef.hasCollections)
 -                        ctypes.set(ctypes.size() - 1, newColType);
 -                    else
 -                        ctypes.add(newColType);
 -                    cfm.comparator = CompositeType.getInstance(ctypes);
 +                    cfm.comparator = cfm.comparator.addOrUpdateCollection(columnName, (CollectionType)type);
                  }
  
 -                Integer componentIndex = cfDef.isComposite
 -                                       ? ((CompositeType)meta.comparator).types.size() -
(cfDef.hasCollections ? 2 : 1)
 -                                       : null;
 +                Integer componentIndex = cfm.comparator.isCompound() ? cfm.comparator.clusteringPrefixSize()
: null;
                  cfm.addColumnDefinition(isStatic
 -                                        ? ColumnDefinition.staticDef(columnName.key, type,
componentIndex)
 -                                        : ColumnDefinition.regularDef(columnName.key, type,
componentIndex));
 +                                        ? ColumnDefinition.staticDef(cfm, columnName.bytes,
type, componentIndex)
 +                                        : ColumnDefinition.regularDef(cfm, columnName.bytes,
type, componentIndex));
                  break;
  
              case ALTER:

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce96a2a1/test/unit/org/apache/cassandra/cql3/AlterTableTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/AlterTableTest.java
index 0000000,0000000..f5747ed
new file mode 100644
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/AlterTableTest.java
@@@ -1,0 -1,0 +1,86 @@@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements.  See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership.  The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License.  You may obtain a copy of the License at
++ *
++ *     http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing, software
++ * distributed under the License is distributed on an "AS IS" BASIS,
++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++ * See the License for the specific language governing permissions and
++ * limitations under the License.
++ */
++package org.apache.cassandra.cql3;
++
++import org.junit.Test;
++
++import org.apache.cassandra.exceptions.InvalidRequestException;
++
++public class AlterTableTest extends CQLTester
++{
++    @Test
++    public void testAddList() throws Throwable
++    {
++        createTable("CREATE TABLE %s (id text PRIMARY KEY, content text);");
++        execute("ALTER TABLE %s ADD myCollection list<text>;");
++        execute("INSERT INTO %s (id, content , myCollection) VALUES ('test', 'first test',
['first element']);");
++
++        assertRows(execute("SELECT * FROM %s;"), row("test", "first test", list("first element")));
++    }
++
++    @Test
++    public void testDropList() throws Throwable
++    {
++        createTable("CREATE TABLE %s (id text PRIMARY KEY, content text, myCollection list<text>);");
++        execute("INSERT INTO %s (id, content , myCollection) VALUES ('test', 'first test',
['first element']);");
++        execute("ALTER TABLE %s DROP myCollection;");
++
++        assertRows(execute("SELECT * FROM %s;"), row("test", "first test"));
++    }
++    @Test
++    public void testAddMap() throws Throwable
++    {
++        createTable("CREATE TABLE %s (id text PRIMARY KEY, content text);");
++        execute("ALTER TABLE %s ADD myCollection map<text, text>;");
++        execute("INSERT INTO %s (id, content , myCollection) VALUES ('test', 'first test',
{ '1' : 'first element'});");
++
++        assertRows(execute("SELECT * FROM %s;"), row("test", "first test", map("1", "first
element")));
++    }
++
++    @Test
++    public void testDropMap() throws Throwable
++    {
++        createTable("CREATE TABLE %s (id text PRIMARY KEY, content text, myCollection map<text,
text>);");
++        execute("INSERT INTO %s (id, content , myCollection) VALUES ('test', 'first test',
{ '1' : 'first element'});");
++        execute("ALTER TABLE %s DROP myCollection;");
++
++        assertRows(execute("SELECT * FROM %s;"), row("test", "first test"));
++    }
++
++    @Test
++    public void testDropListAndAddListWithSameName() throws Throwable
++    {
++        createTable("CREATE TABLE %s (id text PRIMARY KEY, content text, myCollection list<text>);");
++        execute("INSERT INTO %s (id, content , myCollection) VALUES ('test', 'first test',
['first element']);");
++        execute("ALTER TABLE %s DROP myCollection;");
++        execute("ALTER TABLE %s ADD myCollection list<text>;");
++
++        assertRows(execute("SELECT * FROM %s;"), row("test", "first test", null));
++        execute("UPDATE %s set myCollection = ['second element'] WHERE id = 'test';");
++        assertRows(execute("SELECT * FROM %s;"), row("test", "first test", list("second
element")));
++    }
++    @Test
++    public void testDropListAndAddMapWithSameName() throws Throwable
++    {
++        createTable("CREATE TABLE %s (id text PRIMARY KEY, content text, myCollection list<text>);");
++        execute("INSERT INTO %s (id, content , myCollection) VALUES ('test', 'first test',
['first element']);");
++        execute("ALTER TABLE %s DROP myCollection;");
++
++        assertInvalid("ALTER TABLE %s ADD myCollection map<int, int>;");
++    }
++}


Mime
View raw message