cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [2/6] cassandra git commit: Improve IF NOT EXISTS check in CREATE INDEX
Date Thu, 31 Mar 2016 14:47:23 GMT
Improve IF NOT EXISTS check in CREATE INDEX

Patch by Sam Tunnicliffe; reviewed by Benjamin Lerer for CASSANDRA-11331


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

Branch: refs/heads/cassandra-3.5
Commit: be3808140207d2ab783ef907639c2ad544b6683f
Parents: 067c8df
Author: Sam Tunnicliffe <sam@beobal.com>
Authored: Thu Mar 10 17:25:36 2016 +0000
Committer: Sam Tunnicliffe <sam@beobal.com>
Committed: Thu Mar 31 15:37:16 2016 +0100

----------------------------------------------------------------------
 CHANGES.txt                                              |  1 +
 .../cassandra/cql3/statements/CreateIndexStatement.java  | 11 ++++++++---
 .../cql3/validation/entities/SecondaryIndexTest.java     |  4 ++++
 3 files changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/be380814/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index eda762b..7fc628e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.5
+ * Improve IF NOT EXISTS check in CREATE INDEX (CASSANDRA-11131)
  * Upgrade ohc to 0.4.3
  * Enable SO_REUSEADDR for JMX RMI server sockets (CASSANDRA-11093)
  * Allocate merkletrees with the correct size (CASSANDRA-11390)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/be380814/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
index b2a6fd5..df1965a 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
@@ -229,9 +229,14 @@ public class CreateIndexStatement extends SchemaAlteringStatement
         // check to disallow creation of an index which duplicates an existing one in all
but name
         Optional<IndexMetadata> existingIndex = Iterables.tryFind(cfm.getIndexes(),
existing -> existing.equalsWithoutName(index));
         if (existingIndex.isPresent())
-            throw new InvalidRequestException(String.format("Index %s is a duplicate of existing
index %s",
-                                                            index.name,
-                                                            existingIndex.get().name));
+        {
+            if (ifNotExists)
+                return null;
+            else
+                throw new InvalidRequestException(String.format("Index %s is a duplicate
of existing index %s",
+                                                                index.name,
+                                                                existingIndex.get().name));
+        }
 
         logger.trace("Updating index definition for {}", indexName);
         cfm.indexes(cfm.getIndexes().with(index));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/be380814/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
index 6ad9cc8..f9802d7 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
@@ -106,7 +106,11 @@ public class SecondaryIndexTest extends CQLTester
                                            removeQuotes(indexName.toLowerCase(Locale.US))),
                              "CREATE INDEX " + indexName + " ON %s(b)");
 
+        // IF NOT EXISTS should apply in cases where the new index differs from an existing
one in name only
         String otherIndexName = "index_" + System.nanoTime();
+        assertEquals(1, getCurrentColumnFamilyStore().metadata.getIndexes().size());
+        createIndex("CREATE INDEX IF NOT EXISTS " + otherIndexName + " ON %s(b)");
+        assertEquals(1, getCurrentColumnFamilyStore().metadata.getIndexes().size());
         assertInvalidMessage(String.format("Index %s is a duplicate of existing index %s",
                                            removeQuotes(otherIndexName.toLowerCase(Locale.US)),
                                            removeQuotes(indexName.toLowerCase(Locale.US))),


Mime
View raw message