cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject git commit: Add optional keyspace to DROP INDEX statement
Date Tue, 03 Jun 2014 22:33:09 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 fbe4df5e2 -> 6a4144b41


Add optional keyspace to DROP INDEX statement

Patch by Andrés de la Peña; review by Tyler Hobbs for CASSANDRA-7314


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

Branch: refs/heads/cassandra-2.1
Commit: 6a4144b41897b87d824fb76e483d6ce81c62f5ef
Parents: fbe4df5
Author: Tyler Hobbs <tyler@datastax.com>
Authored: Tue Jun 3 17:32:17 2014 -0500
Committer: Tyler Hobbs <tyler@datastax.com>
Committed: Tue Jun 3 17:32:17 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 doc/cql3/CQL.textile                            |  3 +-
 pylib/cqlshlib/cql3handling.py                  | 34 ++++++++--
 src/java/org/apache/cassandra/cql3/Cql.g        | 15 ++++-
 .../org/apache/cassandra/cql3/IndexName.java    | 65 ++++++++++++++++++++
 .../cql3/statements/DropIndexStatement.java     |  6 +-
 6 files changed, 114 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/6a4144b4/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b5c2feb..98e3fc8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,7 @@
  * Upgrade to Pig 0.12.1 (CASSANDRA-6556)
  * Make sure we clear out repair sessions from netstats (CASSANDRA-7329)
  * Don't fail streams on failure detector downs (CASSANDRA-3569)
+ * Add optional keyspace to DROP INDEX statement (CASSANDRA-7314)
 Merged from 2.0:
  * Fix NPE in StreamTransferTask.createMessageForRetry() (CASSANDRA-7323)
  * Make StreamSession#closeSession() idempotent (CASSANDRA-7262)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6a4144b4/doc/cql3/CQL.textile
----------------------------------------------------------------------
diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile
index a89636d..0c1d2b9 100644
--- a/doc/cql3/CQL.textile
+++ b/doc/cql3/CQL.textile
@@ -424,7 +424,8 @@ h3(#createIndexStmt). CREATE INDEX
 
 __Syntax:__
 
-bc(syntax). <create-index-stmt> ::= CREATE ( CUSTOM )? INDEX ( IF NOT EXISTS )? <identifier>?
ON <tablename> '(' <identifier> ')'
+bc(syntax). <create-index-stmt> ::= CREATE ( CUSTOM )? INDEX ( IF NOT EXISTS )? ( (
<keyspacename> '.' )? <indexname> )?
+                                        ON <tablename> '(' <identifier> ')'
                                         ( USING <string> ( WITH OPTIONS = <map-literal>
)? )?
 
 __Sample:__

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6a4144b4/pylib/cqlshlib/cql3handling.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py
index 2710941..a99e8e6 100644
--- a/pylib/cqlshlib/cql3handling.py
+++ b/pylib/cqlshlib/cql3handling.py
@@ -1004,7 +1004,13 @@ syntax_rules += r'''
 <dropColumnFamilyStatement> ::= "DROP" ( "COLUMNFAMILY" | "TABLE" ) ("IF" "EXISTS")?
cf=<columnFamilyName>
                               ;
 
-<dropIndexStatement> ::= "DROP" "INDEX" ("IF" "EXISTS")? indexname=<identifier>
+<indexName> ::= ( ksname=<idxOrKsName> dot="." )? idxname=<idxOrKsName>
;
+
+<idxOrKsName> ::= <identifier>
+               | <quotedName>
+               | <unreservedKeyword>;
+
+<dropIndexStatement> ::= "DROP" "INDEX" ("IF" "EXISTS")? idx=<indexName>
                        ;
 
 <dropUserTypeStatement> ::= "DROP" "TYPE" ut=<userTypeName>
@@ -1012,9 +1018,29 @@ syntax_rules += r'''
 
 '''
 
-@completer_for('dropIndexStatement', 'indexname')
-def drop_index_completer(ctxt, cass):
-    return map(maybe_escape_name, cass.get_index_names())
+@completer_for('indexName', 'ksname')
+def idx_ks_name_completer(ctxt, cass):
+    return [maybe_escape_name(ks) + '.' for ks in cass.get_keyspace_names()]
+
+@completer_for('indexName', 'dot')
+def idx_ks_dot_completer(ctxt, cass):
+    name = dequote_name(ctxt.get_binding('ksname'))
+    if name in cass.get_keyspace_names():
+        return ['.']
+    return []
+
+@completer_for('indexName', 'idxname')
+def idx_ks_idx_name_completer(ctxt, cass):
+    ks = ctxt.get_binding('ksname', None)
+    if ks is not None:
+        ks = dequote_name(ks)
+    try:
+        idxnames = cass.get_index_names(ks)
+    except Exception:
+        if ks is None:
+            return ()
+        raise
+    return map(maybe_escape_name, idxnames)
 
 syntax_rules += r'''
 <alterTableStatement> ::= "ALTER" wat=( "COLUMNFAMILY" | "TABLE" ) cf=<columnFamilyName>

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6a4144b4/src/java/org/apache/cassandra/cql3/Cql.g
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g
index 08d94b0..948cd5e 100644
--- a/src/java/org/apache/cassandra/cql3/Cql.g
+++ b/src/java/org/apache/cassandra/cql3/Cql.g
@@ -684,8 +684,8 @@ dropTypeStatement returns [DropTypeStatement stmt]
  */
 dropIndexStatement returns [DropIndexStatement expr]
     @init { boolean ifExists = false; }
-    : K_DROP K_INDEX (K_IF K_EXISTS { ifExists = true; } )? index=IDENT
-      { $expr = new DropIndexStatement($index.text, ifExists); }
+    : K_DROP K_INDEX (K_IF K_EXISTS { ifExists = true; } )? index=indexName
+      { $expr = new DropIndexStatement(index, ifExists); }
     ;
 
 /**
@@ -823,6 +823,17 @@ keyspaceName returns [String id]
     : cfOrKsName[name, true] { $id = name.getKeyspace(); }
     ;
 
+indexName returns [IndexName name]
+    @init { $name = new IndexName(); }
+    : (idxOrKsName[name, true] '.')? idxOrKsName[name, false]
+    ;
+
+idxOrKsName[IndexName name, boolean isKs]
+    : t=IDENT              { if (isKs) $name.setKeyspace($t.text, false); else $name.setIndex($t.text,
false); }
+    | t=QUOTED_NAME        { if (isKs) $name.setKeyspace($t.text, true); else $name.setIndex($t.text,
true); }
+    | k=unreserved_keyword { if (isKs) $name.setKeyspace(k, false); else $name.setIndex(k,
false); }
+    ;
+
 columnFamilyName returns [CFName name]
     @init { $name = new CFName(); }
     : (cfOrKsName[name, true] '.')? cfOrKsName[name, false]

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6a4144b4/src/java/org/apache/cassandra/cql3/IndexName.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/IndexName.java b/src/java/org/apache/cassandra/cql3/IndexName.java
new file mode 100644
index 0000000..ded86e4
--- /dev/null
+++ b/src/java/org/apache/cassandra/cql3/IndexName.java
@@ -0,0 +1,65 @@
+/*
+ * 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 java.util.Locale;
+
+public class IndexName 
+{
+    private String ksName;
+    private String idxName;
+
+    public void setKeyspace(String ks, boolean keepCase)
+    {
+        ksName = keepCase ? ks : ks.toLowerCase(Locale.US);
+    }
+
+    public void setIndex(String idx, boolean keepCase)
+    {
+        idxName = keepCase ? idx : idx.toLowerCase(Locale.US);
+    }
+
+    public boolean hasKeyspace()
+    {
+        return ksName != null;
+    }
+
+    public String getKeyspace()
+    {
+        return ksName;
+    }
+
+    public String getIdx()
+    {
+        return idxName;
+    }
+
+    public CFName getCfName()
+    {
+        CFName cfName = new CFName();
+        if (hasKeyspace())
+            cfName.setKeyspace(ksName, true);
+    	return cfName;
+    }
+
+    @Override
+    public String toString()
+    {
+        return (hasKeyspace() ? (ksName + ".") : "") + idxName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6a4144b4/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java b/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
index aa17d51..44704a9 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
@@ -33,10 +33,10 @@ public class DropIndexStatement extends SchemaAlteringStatement
     public final String indexName;
     public final boolean ifExists;
 
-    public DropIndexStatement(String indexName, boolean ifExists)
+    public DropIndexStatement(IndexName indexName, boolean ifExists)
     {
-        super(new CFName());
-        this.indexName = indexName;
+        super(indexName.getCfName());
+        this.indexName = indexName.getIdx();
         this.ifExists = ifExists;
     }
 


Mime
View raw message