cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject [2/3] cassandra git commit: Make DropTableStatement throw an error if the table is a view
Date Thu, 17 Sep 2015 19:50:17 GMT
Make DropTableStatement throw an error if the table is a view

patch by Benjamin Lerer; reviewed by Aleksey Yeschenko  for CASSANDRA-10361


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

Branch: refs/heads/trunk
Commit: caadcf69ee3160458db0eae9e3810127709b3717
Parents: a90de7c
Author: blerer <benjamin.lerer@datastax.com>
Authored: Thu Sep 17 21:42:15 2015 +0200
Committer: blerer <benjamin.lerer@datastax.com>
Committed: Thu Sep 17 21:42:15 2015 +0200

----------------------------------------------------------------------
 .../cql3/statements/DropTableStatement.java     |  2 +-
 .../org/apache/cassandra/cql3/ViewTest.java     | 50 ++++++++++++++++----
 2 files changed, 42 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/caadcf69/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java
index 14d89d9..1f61020 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java
@@ -63,7 +63,7 @@ public class DropTableStatement extends SchemaAlteringStatement
         try
         {
             KeyspaceMetadata ksm = Schema.instance.getKSMetaData(keyspace());
-            CFMetaData cfm = ksm.tables.getNullable(columnFamily());
+            CFMetaData cfm = ksm.getTableOrViewNullable(columnFamily());
             if (cfm != null)
             {
                 if (cfm.isView())

http://git-wip-us.apache.org/repos/asf/cassandra/blob/caadcf69/test/unit/org/apache/cassandra/cql3/ViewTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ViewTest.java b/test/unit/org/apache/cassandra/cql3/ViewTest.java
index 9c47707..95662e5 100644
--- a/test/unit/org/apache/cassandra/cql3/ViewTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ViewTest.java
@@ -22,18 +22,16 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.net.InetAddress;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.datastax.driver.core.*;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.exceptions.InvalidQueryException;
 import junit.framework.Assert;
+
 import org.apache.cassandra.concurrent.SEPExecutor;
 import org.apache.cassandra.concurrent.Stage;
 import org.apache.cassandra.concurrent.StageManager;
@@ -46,6 +44,14 @@ import org.apache.cassandra.serializers.SimpleDateSerializer;
 import org.apache.cassandra.serializers.TimeSerializer;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.FBUtilities;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.exceptions.InvalidQueryException;
 
 public class ViewTest extends CQLTester
 {
@@ -1352,4 +1358,30 @@ public class ViewTest extends CQLTester
                       row(2),
                       row(1));
     }
+
+    @Test
+    public void testDropTableWithMV() throws Throwable
+    {
+        createTable("CREATE TABLE %s (" +
+                "a int," +
+                "b int," +
+                "c int," +
+                "d int," +
+                "PRIMARY KEY (a, b, c))");
+
+        executeNet(protocolVersion, "USE " + keyspace());
+
+        createView(keyspace() + ".mv1",
+                   "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE b IS NOT NULL
AND c IS NOT NULL PRIMARY KEY (a, b, c)");
+
+        try
+        {
+            executeNet(protocolVersion, "DROP TABLE " + keyspace() + ".mv1");
+            Assert.fail();
+        }
+        catch (InvalidQueryException e)
+        {
+            Assert.assertEquals("Cannot use DROP TABLE on Materialized View", e.getMessage());
+        }
+    }
 }


Mime
View raw message