cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1124273 - in /cassandra/branches/cassandra-0.8: ./ src/java/org/apache/cassandra/cli/ src/resources/org/apache/cassandra/cli/ test/unit/org/apache/cassandra/cli/
Date Wed, 18 May 2011 14:07:55 GMT
Author: jbellis
Date: Wed May 18 14:07:55 2011
New Revision: 1124273

URL: http://svn.apache.org/viewvc?rev=1124273&view=rev
Log:
add DROP INDEX support to CLI
patch by pyaskevich; reviewed by jbellis for CASSANDRA-2616

Modified:
    cassandra/branches/cassandra-0.8/CHANGES.txt
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/Cli.g
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/CliClient.java
    cassandra/branches/cassandra-0.8/src/resources/org/apache/cassandra/cli/CliHelp.yaml
    cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/cli/CliTest.java

Modified: cassandra/branches/cassandra-0.8/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/CHANGES.txt?rev=1124273&r1=1124272&r2=1124273&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.8/CHANGES.txt Wed May 18 14:07:55 2011
@@ -4,9 +4,10 @@
  * update CQL consistency levels (CASSANDRA-2566)
  * mark BRAF buffer invalid post-flush so we don't re-flush partial
    buffers again, especially on CL writes (CASSANDRA-2660)
+ * add DROP INDEX support to CLI (CASSANDRA-2616)
 
 
-0.8.0-rc1
+0.8.0-rc1 
  * faster flushes and compaction from fixing excessively pessimistic 
    rebuffering in BRAF (CASSANDRA-2581)
  * fix returning null column values in the python cql driver (CASSANDRA-2593)

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/Cli.g
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/Cli.g?rev=1124273&r1=1124272&r2=1124273&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/Cli.g (original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/Cli.g Wed May 18 14:07:55
2011
@@ -61,6 +61,7 @@ tokens {
     NODE_TRUNCATE;
     NODE_ASSUME;
     NODE_CONSISTENCY_LEVEL;
+    NODE_DROP_INDEX;
 
     // Internal Nodes.
     NODE_COLUMN_ACCESS;
@@ -160,6 +161,7 @@ statement
     | truncateStatement
     | assumeStatement
     | consistencyLevelStatement
+    | dropIndex
     | -> ^(NODE_NO_OP)
     ;
 
@@ -203,6 +205,8 @@ helpStatement
         -> ^(NODE_HELP NODE_DEL_KEYSPACE)
     | HELP DROP COLUMN FAMILY 
         -> ^(NODE_HELP NODE_DEL_COLUMN_FAMILY)
+    | HELP DROP INDEX
+        -> ^(NODE_HELP NODE_DROP_INDEX)
     | HELP GET 
         -> ^(NODE_HELP NODE_THRIFT_GET)
     | HELP SET 
@@ -337,6 +341,11 @@ delColumnFamily
         -> ^(NODE_DEL_COLUMN_FAMILY columnFamily)
     ;
 
+dropIndex
+    : DROP INDEX ON columnFamily '.' columnName
+        -> ^(NODE_DROP_INDEX columnFamily columnName)
+    ;
+
 showVersion
     : SHOW API_VERSION
         -> ^(NODE_SHOW_VERSION)
@@ -562,6 +571,8 @@ TRUNCATE:    'TRUNCATE';
 ASSUME:      'ASSUME';
 TTL:         'TTL';
 CONSISTENCYLEVEL:   'CONSISTENCYLEVEL';
+INDEX:       'INDEX';
+ON:          'ON';
 
 IP_ADDRESS 
     : IntegerPositiveLiteral '.' IntegerPositiveLiteral '.' IntegerPositiveLiteral '.' IntegerPositiveLiteral

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/CliClient.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/CliClient.java?rev=1124273&r1=1124272&r2=1124273&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cli/CliClient.java Wed
May 18 14:07:55 2011
@@ -269,6 +269,10 @@ public class CliClient
                 case CliParser.NODE_THRIFT_DECR:
                     executeIncr(tree, -1L);
                     break;
+                case CliParser.NODE_DROP_INDEX:
+                    executeDropIndex(tree);
+                    break;
+
                 case CliParser.NODE_NO_OP:
                     // comment lines come here; they are treated as no ops.
                     break;
@@ -1295,6 +1299,58 @@ public class CliClient
         printSliceList(columnFamilyDef, keySlices);
     }
 
+    // DROP INDEX ON <CF>.<COLUMN>
+    private void executeDropIndex(Tree statement)
+    {
+        if (!CliMain.isConnected() || !hasKeySpace())
+            return;
+
+        // getColumnFamily will check if CF exists for us
+        String columnFamily = CliCompiler.getColumnFamily(statement, keyspacesMap.get(keySpace).cf_defs);
+        String rawColumName = statement.getChild(1).getText();
+
+        CfDef cfDef = getCfDef(columnFamily);
+
+        ByteBuffer columnName = columnNameAsBytes(rawColumName, cfDef);
+
+        boolean foundColumn = false;
+
+        for (ColumnDef column : cfDef.getColumn_metadata())
+        {
+            if (column.name.equals(columnName))
+            {
+                foundColumn = true;
+
+                if (column.getIndex_type() == null)
+                    throw new RuntimeException(String.format("Column '%s' does not have an
index.", rawColumName));
+
+                column.setIndex_name(null);
+                column.setIndex_type(null);
+            }
+        }
+
+        if (!foundColumn)
+            throw new RuntimeException(String.format("Column '%s' definition was not found
in ColumnFamily '%s'.",
+                                                     rawColumName,
+                                                     columnFamily));
+
+        try
+        {
+            String mySchemaVersion = thriftClient.system_update_column_family(cfDef);
+            sessionState.out.println(mySchemaVersion);
+            validateSchemaIsSettled(mySchemaVersion);
+            keyspacesMap.put(keySpace, thriftClient.describe_keyspace(keySpace));
+        }
+        catch (InvalidRequestException e)
+        {
+            System.err.println(e.why);
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
     // TRUNCATE <columnFamily>
     private void executeTruncate(String columnFamily)
     {

Modified: cassandra/branches/cassandra-0.8/src/resources/org/apache/cassandra/cli/CliHelp.yaml
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/resources/org/apache/cassandra/cli/CliHelp.yaml?rev=1124273&r1=1124272&r2=1124273&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/resources/org/apache/cassandra/cli/CliHelp.yaml (original)
+++ cassandra/branches/cassandra-0.8/src/resources/org/apache/cassandra/cli/CliHelp.yaml Wed
May 18 14:07:55 2011
@@ -44,6 +44,7 @@ help: |
     describe keyspace       Describe a keyspace and it's column families.
     drop column family      Remove a column family and it's data.
     drop keyspace           Remove a keyspace and it's data.
+    drop index              Remove an existing index from specific column.
     get                     Get rows and columns.
     incr                    Increments a counter column.
     list                    List rows in a column family.
@@ -827,6 +828,18 @@ commands:
 
         Example:
         drop column family Standard2;
+    - name: NODE_DROP_INDEX
+      help: |
+        drop index on <cf>.<column>;
+
+        Drops index on specified column of the column family.
+
+        Required Parameters:
+          - cf: Name of the column family.
+          - column: Name of the column to delete index on.
+
+        Example:
+        drop index on Users.name;
     - name: NODE_THRIFT_GET
       help: |
         get <cf>['<key>'];

Modified: cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/cli/CliTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/cli/CliTest.java?rev=1124273&r1=1124272&r2=1124273&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/cli/CliTest.java (original)
+++ cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/cli/CliTest.java Wed May
18 14:07:55 2011
@@ -110,6 +110,7 @@ public class CliTest extends CleanupHelp
         "get Counter1['hello']['cassandra'];",
         "get Counter1['hello'];",
         "truncate CF1;",
+        "drop index on CF1.world2;",
         "update keyspace TestKeySpace with placement_strategy='org.apache.cassandra.locator.LocalStrategy';",
         "update keyspace TestKeySpace with strategy_options=[{DC1:3, DC2:4, DC5:1}];",
         "assume CF1 comparator as utf8;",



Mime
View raw message