cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject [1/9] cassandra git commit: Some DROP ... IF EXISTS incorrectly result in exceptions on non-existing KS
Date Fri, 27 Nov 2015 10:02:02 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.1 29178b2fe -> 442d4c9d4


Some DROP ... IF EXISTS incorrectly result in exceptions on non-existing KS

patch by Robert Stupp; reviewed by Marcus Eriksson for CASSANDRA-10658


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

Branch: refs/heads/cassandra-3.1
Commit: 4ecbbc08206fc5cd2e91520a5b99ef890f1da75d
Parents: b8a8004
Author: Robert Stupp <snazy@snazy.de>
Authored: Fri Nov 27 10:42:38 2015 +0100
Committer: Robert Stupp <snazy@snazy.de>
Committed: Fri Nov 27 10:42:38 2015 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cql3/statements/DropTypeStatement.java      | 10 ++++--
 .../cql3/validation/entities/TypeTest.java      | 10 ++++++
 .../cql3/validation/operations/DropTest.java    | 37 ++++++++++++++++++++
 4 files changed, 56 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ecbbc08/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 48f4e89..4adcf4f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.12
+ * Some DROP ... IF EXISTS incorrectly result in exceptions on non-existing KS (CASSANDRA-10658)
  * DeletionTime.compareTo wrong in rare cases (CASSANDRA-10749)
  * Force encoding when computing statement ids (CASSANDRA-10755)
  * Properly reject counters as map keys (CASSANDRA-10760)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ecbbc08/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java b/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java
index 94edd01..bc6005d 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropTypeStatement.java
@@ -54,7 +54,12 @@ public class DropTypeStatement extends SchemaAlteringStatement
     {
         KSMetaData ksm = Schema.instance.getKSMetaData(name.getKeyspace());
         if (ksm == null)
-            throw new InvalidRequestException(String.format("Cannot drop type in unknown
keyspace %s", name.getKeyspace()));
+        {
+            if (ifExists)
+                return;
+            else
+                throw new InvalidRequestException(String.format("Cannot drop type in unknown
keyspace %s", name.getKeyspace()));
+        }
 
         UserType old = ksm.userTypes.getType(name.getUserTypeName());
         if (old == null)
@@ -140,7 +145,8 @@ public class DropTypeStatement extends SchemaAlteringStatement
     public boolean announceMigration(boolean isLocalOnly) throws InvalidRequestException,
ConfigurationException
     {
         KSMetaData ksm = Schema.instance.getKSMetaData(name.getKeyspace());
-        assert ksm != null;
+        if (ksm == null)
+            return false; // do not assert (otherwise IF EXISTS case fails)
 
         UserType toDrop = ksm.userTypes.getType(name.getUserTypeName());
         // Can be null with ifExists

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ecbbc08/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java
index f27cca8..f23ce35 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/TypeTest.java
@@ -28,6 +28,16 @@ import static org.junit.Assert.fail;
 public class TypeTest extends CQLTester
 {
     @Test
+    public void testNonExistingOnes() throws Throwable
+    {
+        assertInvalidMessage("No user type named", "DROP TYPE " + KEYSPACE + ".type_does_not_exist");
+        assertInvalidMessage("Cannot drop type in unknown keyspace", "DROP TYPE keyspace_does_not_exist.type_does_not_exist");
+
+        execute("DROP TYPE IF EXISTS " + KEYSPACE + ".type_does_not_exist");
+        execute("DROP TYPE IF EXISTS keyspace_does_not_exist.type_does_not_exist");
+    }
+
+    @Test
     public void testNowToUUIDCompatibility() throws Throwable
     {
         createTable("CREATE TABLE %s (a int, b uuid, PRIMARY KEY (a, b))");

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ecbbc08/test/unit/org/apache/cassandra/cql3/validation/operations/DropTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/DropTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/DropTest.java
new file mode 100644
index 0000000..b0c0809
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/DropTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.validation.operations;
+
+import org.junit.Test;
+
+import org.apache.cassandra.cql3.CQLTester;
+
+public class DropTest extends CQLTester
+{
+    @Test
+    public void testNonExistingOnes() throws Throwable
+    {
+        assertInvalidMessage("Cannot drop non existing column family", "DROP TABLE " + KEYSPACE
+ ".table_does_not_exist");
+        assertInvalidMessage("Cannot drop non existing column family", "DROP TABLE keyspace_does_not_exist.table_does_not_exist");
+
+        execute("DROP TABLE IF EXISTS " + KEYSPACE + ".table_does_not_exist");
+        execute("DROP TABLE IF EXISTS keyspace_does_not_exist.table_does_not_exist");
+    }
+
+}


Mime
View raw message