cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject svn commit: r1084616 - in /cassandra/trunk: src/java/org/apache/cassandra/cli/ test/unit/org/apache/cassandra/cli/
Date Wed, 23 Mar 2011 15:41:22 GMT
Author: brandonwilliams
Date: Wed Mar 23 15:41:21 2011
New Revision: 1084616

URL: http://svn.apache.org/viewvc?rev=1084616&view=rev
Log:
Add counter support to the cli.
Patch by Sylvain Lebresne, reviewed by Pavel Yaskevich for
CASSANDRA-2341.

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g
    cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
    cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java
    cassandra/trunk/src/java/org/apache/cassandra/cli/CliUserHelp.java
    cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g?rev=1084616&r1=1084615&r2=1084616&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g Wed Mar 23 15:41:21 2011
@@ -49,6 +49,8 @@ tokens {
     NODE_THRIFT_SET;
     NODE_THRIFT_COUNT;
     NODE_THRIFT_DEL;
+    NODE_THRIFT_INCR;
+    NODE_THRIFT_DECR;
     NODE_ADD_COLUMN_FAMILY;
     NODE_ADD_KEYSPACE;
     NODE_DEL_KEYSPACE;
@@ -152,6 +154,7 @@ statement
     | getStatement
     | helpStatement
     | setStatement
+    | incrStatement
     | showStatement
     | listStatement
     | truncateStatement
@@ -204,6 +207,10 @@ helpStatement
         -> ^(NODE_HELP NODE_THRIFT_GET)
     | HELP SET 
         -> ^(NODE_HELP NODE_THRIFT_SET)
+    | HELP INCR
+        -> ^(NODE_HELP NODE_THRIFT_INCR)
+    | HELP DECR
+        -> ^(NODE_HELP NODE_THRIFT_DECR)
     | HELP DEL 
         -> ^(NODE_HELP NODE_THRIFT_DEL)
     | HELP COUNT 
@@ -230,7 +237,7 @@ exitStatement
 getStatement
     : GET columnFamilyExpr ('AS' typeIdentifier)?
         -> ^(NODE_THRIFT_GET columnFamilyExpr ( ^(CONVERT_TO_TYPE typeIdentifier) )? )
-    | GET columnFamily 'WHERE' getCondition ('AND' getCondition)* ('LIMIT' limit=IntegerLiteral)*
+    | GET columnFamily 'WHERE' getCondition ('AND' getCondition)* ('LIMIT' limit=IntegerPositiveLiteral)*
         -> ^(NODE_THRIFT_GET_WITH_CONDITIONS columnFamily ^(CONDITIONS getCondition+)
^(NODE_LIMIT $limit)*) 
     ;
 
@@ -244,14 +251,21 @@ operator
     ;
 
 typeIdentifier
-    : Identifier | StringLiteral | IntegerLiteral 
+    : Identifier | StringLiteral | IntegerPositiveLiteral 
     ;
 
 setStatement
-    : SET columnFamilyExpr '=' objectValue=value (WITH TTL '=' ttlValue=value)?
+    : SET columnFamilyExpr '=' objectValue=value (WITH TTL '=' ttlValue=IntegerPositiveLiteral)?
         -> ^(NODE_THRIFT_SET columnFamilyExpr $objectValue ( $ttlValue )?)
     ;
 
+incrStatement
+    : INCR columnFamilyExpr (BY byValue=incrementValue)?
+        -> ^(NODE_THRIFT_INCR columnFamilyExpr ( $byValue )?)
+    | DECR columnFamilyExpr (BY byValue=incrementValue)?
+        -> ^(NODE_THRIFT_DECR columnFamilyExpr ( $byValue )?)
+    ;
+
 countStatement
     : COUNT columnFamilyExpr 
         -> ^(NODE_THRIFT_COUNT columnFamilyExpr)
@@ -269,7 +283,7 @@ showStatement
     ;
 
 listStatement
-    : LIST columnFamily keyRangeExpr? ('LIMIT' limit=IntegerLiteral)?
+    : LIST columnFamily keyRangeExpr? ('LIMIT' limit=IntegerPositiveLiteral)?
         -> ^(NODE_LIST columnFamily keyRangeExpr? ^(NODE_LIMIT $limit)?)
     ;
 
@@ -408,7 +422,7 @@ attrValueString
 	;
       
 attrValueInt
-	: IntegerLiteral
+	: IntegerPositiveLiteral
 	;
 
 attrValueDouble
@@ -428,7 +442,7 @@ replica_placement_strategy
 	;
 
 replication_factor
-	: IntegerLiteral
+	: IntegerPositiveLiteral
 	;
 
 keyspaceNewName
@@ -457,11 +471,11 @@ columnFamily
 	;
 
 rowKey	
-    :  (Identifier | StringLiteral | IntegerLiteral | functionCall)
+    :  (Identifier | StringLiteral | IntegerPositiveLiteral | functionCall)
 	;
 
 value	
-    : (Identifier | IntegerLiteral | StringLiteral | functionCall)
+    : (Identifier | IntegerPositiveLiteral | StringLiteral | functionCall)
 	;
 
 functionCall 
@@ -470,7 +484,7 @@ functionCall 
     ;
 
 functionArgument 
-    : Identifier | StringLiteral | IntegerLiteral
+    : Identifier | StringLiteral | IntegerPositiveLiteral
     ;
 
 startKey
@@ -482,7 +496,7 @@ endKey	
 	;
 
 columnOrSuperColumn
-	: (Identifier | IntegerLiteral | StringLiteral | functionCall)
+	: (Identifier | IntegerPositiveLiteral | StringLiteral | functionCall)
 	;
 
 host	
@@ -501,9 +515,14 @@ ip_address
 
 
 port	
-    : IntegerLiteral
+    : IntegerPositiveLiteral
 	;
 
+incrementValue
+    : IntegerNegativeLiteral
+    | IntegerPositiveLiteral
+    ;
+
 //
 // Lexer Section
 //
@@ -526,6 +545,8 @@ EXIT:        'EXIT';
 FILE:        'FILE';
 QUIT:        'QUIT';
 SET:         'SET';
+INCR:        'INCR';
+DECR:        'DECR';
 SHOW:        'SHOW';
 KEYSPACE:    'KEYSPACE';
 KEYSPACES:   'KEYSPACES';
@@ -535,6 +556,7 @@ DROP:        'DROP';
 COLUMN:      'COLUMN';
 FAMILY:      'FAMILY';
 WITH:        'WITH';
+BY:          'BY';
 AND:         'AND';
 UPDATE:      'UPDATE';
 LIST:        'LIST';
@@ -545,7 +567,7 @@ TTL:         'TTL';
 CONSISTENCYLEVEL:   'CONSISTENCYLEVEL';
 
 IP_ADDRESS 
-    : IntegerLiteral '.' IntegerLiteral '.' IntegerLiteral '.' IntegerLiteral
+    : IntegerPositiveLiteral '.' IntegerPositiveLiteral '.' IntegerPositiveLiteral '.' IntegerPositiveLiteral
     ;
 
 // private syntactic rules
@@ -567,9 +589,13 @@ Alnum
     ;
 
 // syntactic Elements
-IntegerLiteral
+IntegerPositiveLiteral
    : Digit+
    ;
+
+IntegerNegativeLiteral
+   : '-' Digit+
+   ;
    
 DoubleLiteral
    : Digit+ '.' Digit+;

Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java?rev=1084616&r1=1084615&r2=1084616&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java Wed Mar 23 15:41:21 2011
@@ -195,6 +195,11 @@ public class CliClient extends CliUserHe
                     break;
                 case CliParser.NODE_CONSISTENCY_LEVEL:
                     executeConsistencyLevelStatement(tree);
+                case CliParser.NODE_THRIFT_INCR:
+                    executeIncr(tree, 1L);
+                    break;
+                case CliParser.NODE_THRIFT_DECR:
+                    executeIncr(tree, -1L);
                     break;
                 case CliParser.NODE_NO_OP:
                     // comment lines come here; they are treated as no ops.
@@ -308,8 +313,15 @@ public class CliClient extends CliUserHe
         if (columnName != null)
             path.setColumn(columnName);
 
-        thriftClient.remove(ByteBuffer.wrap(key.getBytes(Charsets.UTF_8)), path,
-                             FBUtilities.timestampMicros(), consistencyLevel);
+        if (isCounterCF(cfDef))
+        {
+            thriftClient.remove_counter(ByteBuffer.wrap(key.getBytes(Charsets.UTF_8)), path,
consistencyLevel);
+        }
+        else
+        {
+            thriftClient.remove(ByteBuffer.wrap(key.getBytes(Charsets.UTF_8)), path,
+                    FBUtilities.timestampMicros(), consistencyLevel);
+        }
         sessionState.out.println(String.format("%s removed.", (columnSpecCnt == 0) ? "row"
: "column"));
     }
 
@@ -322,12 +334,20 @@ public class CliClient extends CliUserHe
             parent.setSuper_column(superColumnName);
 
         SliceRange range = new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER,
false, 1000000);
-        List<ColumnOrSuperColumn> columns = thriftClient.get_slice(key, parent, new
SlicePredicate().setColumn_names(null).setSlice_range(range), consistencyLevel);
+        SlicePredicate predicate = new SlicePredicate().setColumn_names(null).setSlice_range(range);
 
-        AbstractType validator;
         CfDef cfDef = getCfDef(columnFamily);
         boolean isSuperCF = cfDef.column_type.equals("Super");
 
+        if (isCounterCF(cfDef))
+        {
+            doCounterSlice(keyspace, key, parent, predicate, isSuperCF);
+            return;
+        }
+
+        List<ColumnOrSuperColumn> columns = thriftClient.get_slice(key, parent, predicate,
consistencyLevel);
+        AbstractType validator;
+
         // Print out super columns or columns.
         for (ColumnOrSuperColumn cosc : columns)
         {
@@ -335,11 +355,11 @@ public class CliClient extends CliUserHe
             {
                 SuperColumn superColumn = cosc.super_column;
 
-                sessionState.out.printf("=> (super_column=%s,", formatSuperColumnName(keyspace,
columnFamily, superColumn));
+                sessionState.out.printf("=> (super_column=%s,", formatColumnName(keyspace,
columnFamily, superColumn.name));
                 for (Column col : superColumn.getColumns())
                 {
                     validator = getValidatorForValue(cfDef, col.getName());
-                    sessionState.out.printf("%n     (column=%s, value=%s, timestamp=%d%s)",
formatSubcolumnName(keyspace, columnFamily, col),
+                    sessionState.out.printf("%n     (column=%s, value=%s, timestamp=%d%s)",
formatSubcolumnName(keyspace, columnFamily, col.name),
                                                     validator.getString(col.value), col.timestamp,
                                                     col.isSetTtl() ? String.format(", ttl=%d",
col.getTtl()) : "");
                 }
@@ -352,8 +372,8 @@ public class CliClient extends CliUserHe
                 validator = getValidatorForValue(cfDef, column.getName());
 
                 String formattedName = isSuperCF
-                                       ? formatSubcolumnName(keyspace, columnFamily, column)
-                                       : formatColumnName(keyspace, columnFamily, column);
+                                       ? formatSubcolumnName(keyspace, columnFamily, column.name)
+                                       : formatColumnName(keyspace, columnFamily, column.name);
 
                 sessionState.out.printf("=> (column=%s, value=%s, timestamp=%d%s)%n",
                                         formattedName,
@@ -366,6 +386,40 @@ public class CliClient extends CliUserHe
         sessionState.out.println("Returned " + columns.size() + " results.");
     }
 
+    private void doCounterSlice(String keyspace, ByteBuffer key, ColumnParent parent, SlicePredicate
predicate, boolean isSuperCF)
+            throws InvalidRequestException, UnavailableException, TimedOutException, TException,
IllegalAccessException, NotFoundException, InstantiationException, NoSuchFieldException
+    {
+        String columnFamily = parent.column_family;
+        List<Counter> columns = thriftClient.get_counter_slice(key, parent, predicate,
consistencyLevel);
+
+        // Print out super columns or columns.
+        for (Counter cosc : columns)
+        {
+            if (cosc.isSetSuper_column())
+            {
+                CounterSuperColumn superColumn = cosc.super_column;
+
+                sessionState.out.printf("=> (super_column=%s,", formatColumnName(keyspace,
columnFamily, superColumn.name));
+                for (CounterColumn col : superColumn.getColumns())
+                {
+                    sessionState.out.printf("%n     (counter=%s, value=%s)", formatSubcolumnName(keyspace,
columnFamily, col.name), col.value);
+                }
+                sessionState.out.println(")");
+            }
+            else
+            {
+                CounterColumn column = cosc.column;
+                String formattedName = isSuperCF
+                                       ? formatSubcolumnName(keyspace, columnFamily, column.name)
+                                       : formatColumnName(keyspace, columnFamily, column.name);
+
+                sessionState.out.printf("=> (counter=%s, value=%s)%n", formattedName,
column.value);
+            }
+        }
+        
+        sessionState.out.println("Returned " + columns.size() + " results.");
+    }
+
     private AbstractType getFormatTypeForColumn(String compareWith)
     {
         Function function;
@@ -440,11 +494,18 @@ public class CliClient extends CliUserHe
         }
 
         AbstractType validator = getValidatorForValue(cfDef, TBaseHelper.byteBufferToByteArray(columnName));
-        
+
         // Perform a get()
         ColumnPath path = new ColumnPath(columnFamily);
         if(superColumnName != null) path.setSuper_column(superColumnName);
         path.setColumn(columnName);
+
+        if (isCounterCF(cfDef))
+        {
+            doGetCounter(key, path);
+            return;
+        }
+
         Column column;
         try
         {
@@ -482,8 +543,8 @@ public class CliClient extends CliUserHe
         }
 
         String formattedColumnName = isSuper
-                                     ? formatSubcolumnName(keySpace, columnFamily, column)
-                                     : formatColumnName(keySpace, columnFamily, column);
+                                     ? formatSubcolumnName(keySpace, columnFamily, column.name)
+                                     : formatColumnName(keySpace, columnFamily, column.name);
 
         // print results
         sessionState.out.printf("=> (column=%s, value=%s, timestamp=%d%s)%n",
@@ -493,6 +554,32 @@ public class CliClient extends CliUserHe
                                 column.isSetTtl() ? String.format(", ttl=%d", column.getTtl())
: "");
     }
 
+    private void doGetCounter(ByteBuffer key, ColumnPath path)
+            throws TException, NotFoundException, InvalidRequestException, UnavailableException,
TimedOutException, IllegalAccessException, InstantiationException, ClassNotFoundException,
NoSuchFieldException
+    {
+        boolean isSuper = path.super_column != null;
+
+        CounterColumn column;
+        try
+        {
+            column = thriftClient.get_counter(key, path, consistencyLevel).column;
+        }
+        catch (NotFoundException e)
+        {
+            sessionState.out.println("Value was not found");
+            return;
+        }
+
+        String formattedColumnName = isSuper
+                                     ? formatSubcolumnName(keySpace, path.column_family,
column.name)
+                                     : formatColumnName(keySpace, path.column_family, column.name);
+
+        // print results
+        sessionState.out.printf("=> (counter=%s, value=%d)%n",
+                                formattedColumnName,
+                                column.value);
+    }
+
     /**
      * Process get operation with conditions (using Thrift get_indexed_slices method)
      * @param statement - tree representation of the current statement
@@ -675,6 +762,75 @@ public class CliClient extends CliUserHe
         sessionState.out.println("Value inserted.");
     }
 
+    // Execute INCR statement
+    private void executeIncr(Tree statement, long multiplier)
+            throws TException, NotFoundException, InvalidRequestException, UnavailableException,
TimedOutException, IllegalAccessException, InstantiationException, ClassNotFoundException,
NoSuchFieldException
+    {
+        if (!CliMain.isConnected() || !hasKeySpace())
+            return;
+
+        Tree columnFamilySpec = statement.getChild(0);
+
+        String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, keyspacesMap.get(keySpace).cf_defs);
+        ByteBuffer key = getKeyAsBytes(columnFamily, columnFamilySpec.getChild(1));
+        int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
+        CfDef cfDef = getCfDef(columnFamily);
+        boolean isSuper = cfDef.column_type.equals("Super");
+        
+        byte[] superColumnName = null;
+        ByteBuffer columnName;
+
+        // table.cf['key']['column'] -- incr standard
+        if (columnSpecCnt == 1)
+        {
+            columnName = getColumnName(columnFamily, columnFamilySpec.getChild(2));
+        }
+        // table.cf['key']['column']['column'] -- incr super
+        else if (columnSpecCnt == 2)
+        {
+            superColumnName = getColumnName(columnFamily, columnFamilySpec.getChild(2)).array();
+            columnName = getSubColumnName(columnFamily, columnFamilySpec.getChild(3));
+        }
+        // The parser groks an arbitrary number of these so it is possible to get here.
+        else
+        {
+            sessionState.out.println("Invalid row, super column, or column specification.");
+            return;
+        }
+
+        ColumnParent parent = new ColumnParent(columnFamily);
+        if(superColumnName != null)
+            parent.setSuper_column(superColumnName);
+
+        long value = 1L;
+
+        // children count = 3 mean that we have by in arguments
+        if (statement.getChildCount() == 2)
+        {
+            String byValue = statement.getChild(1).getText();
+
+            try
+            {
+                value = Long.parseLong(byValue);
+            }
+            catch (NumberFormatException e)
+            {
+                sessionState.err.println(String.format("'%s' is an invalid value, should
be an integer.", byValue));
+                return;
+            }
+            catch (Exception e)
+            {
+                throw new RuntimeException(e.getMessage());
+            }
+        }
+
+        CounterColumn columnToInsert = new CounterColumn(columnName, multiplier * value);
+
+        // do the insert
+        thriftClient.add(key, parent, columnToInsert, consistencyLevel);
+        sessionState.out.printf("Value %s%n", multiplier < 0 ? "decremented." : "incremented.");
+    }
+
     private void executeShowClusterName() throws TException
     {
         if (!CliMain.isConnected())
@@ -2053,20 +2209,20 @@ public class CliClient extends CliUserHe
                     validator = getValidatorForValue(columnFamilyDef, col.getName());
 
                     sessionState.out.printf("=> (column=%s, value=%s, timestamp=%d%s)%n",
-                                    formatColumnName(keySpace, columnFamilyName, col), validator.getString(col.value),
col.timestamp,
+                                    formatColumnName(keySpace, columnFamilyName, col.name),
validator.getString(col.value), col.timestamp,
                                     col.isSetTtl() ? String.format(", ttl=%d", col.getTtl())
: "");
                 }
                 else if (columnOrSuperColumn.super_column != null)
                 {
                     SuperColumn superCol = columnOrSuperColumn.super_column;
-                    sessionState.out.printf("=> (super_column=%s,", formatSuperColumnName(keySpace,
columnFamilyName, superCol));
+                    sessionState.out.printf("=> (super_column=%s,", formatColumnName(keySpace,
columnFamilyName, superCol.name));
 
                     for (Column col : superCol.columns)
                     {
                         validator = getValidatorForValue(columnFamilyDef, col.getName());
 
                         sessionState.out.printf("%n     (column=%s, value=%s, timestamp=%d%s)",
-                                        formatSubcolumnName(keySpace, columnFamilyName, col),
validator.getString(col.value), col.timestamp,
+                                        formatSubcolumnName(keySpace, columnFamilyName, col.name),
validator.getString(col.value), col.timestamp,
                                         col.isSetTtl() ? String.format(", ttl=%d", col.getTtl())
: "");
                     }
 
@@ -2078,25 +2234,18 @@ public class CliClient extends CliUserHe
         sessionState.out.printf("%n%d Row%s Returned.%n", slices.size(), (slices.size() >
1 ? "s" : ""));
     }
 
-    // returnsub-columnmn name in human-readable format
-    private String formatSuperColumnName(String keyspace, String columnFamily, SuperColumn
column)
-            throws NotFoundException, TException, IllegalAccessException, InstantiationException,
NoSuchFieldException
-    {
-        return getFormatTypeForColumn(getCfDef(keyspace,columnFamily).comparator_type).getString(column.name);
-    }
-
     // retuns sub-column name in human-readable format
-    private String formatSubcolumnName(String keyspace, String columnFamily, Column subcolumn)
+    private String formatSubcolumnName(String keyspace, String columnFamily, ByteBuffer name)
             throws NotFoundException, TException, IllegalAccessException, InstantiationException,
NoSuchFieldException
     {
-        return getFormatTypeForColumn(getCfDef(keyspace,columnFamily).subcomparator_type).getString(subcolumn.name);
+        return getFormatTypeForColumn(getCfDef(keyspace,columnFamily).subcomparator_type).getString(name);
     }
 
     // retuns column name in human-readable format
-    private String formatColumnName(String keyspace, String columnFamily, Column column)
+    private String formatColumnName(String keyspace, String columnFamily, ByteBuffer name)
             throws NotFoundException, TException, IllegalAccessException, InstantiationException,
NoSuchFieldException
     {
-        return getFormatTypeForColumn(getCfDef(keyspace, columnFamily).comparator_type).getString(ByteBuffer.wrap(column.getName()));
+        return getFormatTypeForColumn(getCfDef(keyspace, columnFamily).comparator_type).getString(name);
     }
 
     private ByteBuffer getColumnName(String columnFamily, Tree columnTree)
@@ -2179,4 +2328,14 @@ public class CliClient extends CliUserHe
             return a.name.compareTo(b.name);
         }
     }
+
+    private boolean isCounterCF(CfDef cfdef)
+    {
+        String defaultValidator = cfdef.default_validation_class;
+        if (defaultValidator != null && !defaultValidator.isEmpty())
+        {
+            return (getFormatTypeForColumn(defaultValidator) instanceof CounterColumnType);
+        }
+        return false;
+    }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java?rev=1084616&r1=1084615&r2=1084616&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompleter.java Wed Mar 23 15:41:21
2011
@@ -66,7 +66,9 @@ public class CliCompleter extends Simple
             "count",
             "del",
             "list",
-            "truncate"
+            "truncate",
+            "incr",
+            "decr"
     };
 
     public CliCompleter()

Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliUserHelp.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliUserHelp.java?rev=1084616&r1=1084615&r2=1084616&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliUserHelp.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliUserHelp.java Wed Mar 23 15:41:21
2011
@@ -279,6 +279,24 @@ public class CliUserHelp {
                 state.out.println("set diz[testkey][testcol] = 'this is utf8 string.' with
ttl = 150;");
                 break;
 
+            case CliParser.NODE_THRIFT_INCR:
+                state.out.println("incr <cf>['<key>']['<col>'] [by <value>];");
+                state.out.println("incr <cf>['<key>']['<super>']['<col>']
[by <value>];");
+                state.out.println("examples:");
+                state.out.println("incr bar['testkey']['my super']['test col'];");
+                state.out.println("incr bar['testkey']['my super']['test col'] by 42;");
+                state.out.println("incr baz['testkey']['test col'] by -4;");
+                break;
+
+            case CliParser.NODE_THRIFT_DECR:
+                state.out.println("decr <cf>['<key>']['<col>'] [by <value>];");
+                state.out.println("decr <cf>['<key>']['<super>']['<col>']
[by <value>];");
+                state.out.println("examples:");
+                state.out.println("decr bar['testkey']['my super']['test col'];");
+                state.out.println("decr bar['testkey']['my super']['test col'] by 42;");
+                state.out.println("decr baz['testkey']['test col'] by 10;");
+                break;
+
             case CliParser.NODE_THRIFT_DEL:
                 state.out.println("del <cf>['<key>'];");
                 state.out.println("del <cf>['<key>']['<col>'];");
@@ -375,6 +393,12 @@ public class CliUserHelp {
             state.out.println("del <cf>['<key>']['<super>']['<col>'];
                       Delete sub column.");
             state.out.println("count <cf>['<key>'];                         
          Count columns in record.");
             state.out.println("count <cf>['<key>']['<super>'];        
        Count columns in a super column.");
+            state.out.println("incr <cf>['<key>']['<col>'] [by <value>];
           Increment a counter column.");
+            state.out.println("incr <cf>['<key>']['<super>']['<col>']
[by <value>];");
+            state.out.println("                                                 Increment
a counter sub-column.");
+            state.out.println("decr <cf>['<key>']['<col>'] [by <value>];
           Decrement a counter column.");
+            state.out.println("decr <cf>['<key>']['<super>']['<col>']
[by <value>];");
+            state.out.println("                                                 Decrement
a counter sub-column.");
             state.out.println("truncate <column_family>;                      Truncate
specified column family.");
             state.out.println("assume <column_family> <attribute> as <type>;");
             state.out.println("              Assume a given column family attributes to match
a specified type.");

Modified: cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java?rev=1084616&r1=1084615&r2=1084616&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java Wed Mar 23 15:41:21 2011
@@ -86,6 +86,16 @@ public class CliTest extends CleanupHelp
         "set SCF1['hello'][1][9999] = Long(1234);",
         "del SCF1['hello'][9999];",
         "get SCF1['hello'][1][9999];",
+        "create column family Counter1 with comparator=UTF8Type and default_validation_class=CounterColumnType;",
+        "assume Counter1 keys as utf8;",
+        "incr Counter1['hello']['cassandra'];",
+        "incr Counter1['hello']['cassandra'] by 3;",
+        "incr Counter1['hello']['cassandra'] by -2;",
+        "decr Counter1['hello']['cassandra'];",
+        "decr Counter1['hello']['cassandra'] by 3;",
+        "decr Counter1['hello']['cassandra'] by -2;",
+        "get Counter1['hello']['cassandra'];",
+        "get Counter1['hello'];",
         "truncate CF1;",
         "update keyspace TestKeySpace with placement_strategy='org.apache.cassandra.locator.LocalStrategy';",
         "update keyspace TestKeySpace with replication_factor=1 and strategy_options=[{DC1:3,
DC2:4, DC5:1}];",
@@ -122,6 +132,7 @@ public class CliTest extends CleanupHelp
         "get Countries[1][name];",
         "set myCF['key']['scName']['firstname'] = 'John';",
         "get myCF['key']['scName']",
+        "assume CF3 keys as utf8;",
         "use TestKEYSpace;",
         "describe cluster;",
         "help describe cluster;",
@@ -190,12 +201,24 @@ public class CliTest extends CleanupHelp
             {
                 assertEquals(result, "Value inserted." + System.getProperty("line.separator"));
             }
+            else if (statement.startsWith("incr "))
+            {
+                assertEquals(result, "Value incremented." + System.getProperty("line.separator"));
+            }
+            else if (statement.startsWith("decr "))
+            {
+                assertEquals(result, "Value decremented." + System.getProperty("line.separator"));
+            }
             else if (statement.startsWith("get "))
             {
                 if (statement.contains("where"))
                 {
                     assertTrue(result.startsWith("-------------------" + System.getProperty("line.separator")
+ "RowKey:"));
                 }
+                else if (statement.contains("Counter"))
+                {
+                    assertTrue(result.startsWith("=> (counter=") || result.startsWith("Value
was not found"));
+                }
                 else
                 {
                     assertTrue(result.startsWith("=> (column=") || result.startsWith("Value
was not found"));



Mime
View raw message