cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r888628 - /incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
Date Tue, 08 Dec 2009 23:33:51 GMT
Author: eevans
Date: Tue Dec  8 23:33:51 2009
New Revision: 888628

URL: http://svn.apache.org/viewvc?rev=888628&view=rev
Log:
super column support for deletes

Patch by eevans; reviewed by jbellis

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java?rev=888628&r1=888627&r2=888628&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java Tue Dec  8
23:33:51 2009
@@ -26,6 +26,7 @@
 import java.io.UnsupportedEncodingException;
 
 import org.apache.commons.lang.ArrayUtils;
+import org.hamcrest.core.IsSame;
 
 // Cli Client Side Library
 public class CliClient 
@@ -121,7 +122,8 @@
        css_.out.println("set <ksp>.<cf>['<key>']['<super>']['<col>']
= '<value>'        Set a sub column.");
        css_.out.println("del <ksp>.<cf>['<key>']                      
                    Delete record.");
        css_.out.println("del <ksp>.<cf>['<key>']['<col>']       
                          Delete column.");
-       css_.out.println("count <ksp>.<cf>['<key>']                    
             Count columns in row.");
+       css_.out.println("del <ksp>.<cf>['<key>']['<super>']['<col>']
                  Delete sub column.");
+       css_.out.println("count <ksp>.<cf>['<key>']                    
          Count columns in record.");
     }
 
     private void cleanupAndExit()
@@ -184,22 +186,49 @@
         String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
         int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
 
-        // assume simple columnFamily for now
-        String columnName = null;
-        final byte[] name;
-        if (columnSpecCnt == 0)
+        byte[] superColumnName = null;
+        byte[] columnName = null;
+        boolean isSuper;
+        
+        try
         {
-            // table.cf['key']
-            name = null;
+            if (!(getCFMetaData(tableName).containsKey(columnFamily)))
+            {
+                css_.out.println("No such column family: " + columnFamily);
+                return;
+            }
+            
+            isSuper = getCFMetaData(tableName).get(columnFamily).get("Type").equals("Super")
? true : false;
         }
-        else
+        catch (NotFoundException nfe)
+        {
+            css_.out.printf("No such keyspace: %s\n", tableName);
+            return;
+        }
+     
+        if ((columnSpecCnt < 0) || (columnSpecCnt > 2))
+        {
+            css_.out.println("Invalid row, super column, or column specification.");
+            return;
+        }
+        
+        if (columnSpecCnt == 1)
         {
-            assert columnSpecCnt == 1;
             // table.cf['key']['column']
-            columnName = CliCompiler.getColumn(columnFamilySpec, 0);
-            name = columnName.getBytes("UTF-8");
+            if (isSuper)
+                superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
+            else
+                columnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
         }
-        thriftClient_.remove(tableName, key, new ColumnPath(columnFamily, null, name), System.currentTimeMillis(),
ConsistencyLevel.ONE);
+        else if (columnSpecCnt == 2)
+        {
+            // table.cf['key']['column']['column']
+            superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
+            columnName = CliCompiler.getColumn(columnFamilySpec, 1).getBytes("UTF-8");
+        }
+        
+        thriftClient_.remove(tableName, key, new ColumnPath(columnFamily, superColumnName,
columnName),
+                             System.currentTimeMillis(), ConsistencyLevel.ONE);
         css_.out.println(String.format("%s removed.", (columnSpecCnt == 0) ? "row" : "column"));
     }  
     



Mime
View raw message