cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject svn commit: r1124780 - in /cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli: Cli.g CliClient.java
Date Thu, 19 May 2011 13:53:06 GMT
Author: slebresne
Date: Thu May 19 13:53:06 2011
New Revision: 1124780

URL: http://svn.apache.org/viewvc?rev=1124780&view=rev
Log:
Allow limiting row slices in the cli
patch by slebresne; reviewed by xedin for CASSANDRA-2646

Modified:
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g?rev=1124780&r1=1124779&r2=1124780&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g Thu May 19 13:53:06
2011
@@ -228,10 +228,10 @@ exitStatement
     ;
 
 getStatement
-    : GET columnFamilyExpr ('AS' typeIdentifier)?
-        -> ^(NODE_THRIFT_GET columnFamilyExpr ( ^(CONVERT_TO_TYPE typeIdentifier) )? )
-    | GET columnFamily 'WHERE' getCondition ('AND' getCondition)* ('LIMIT' limit=IntegerLiteral)*
-        -> ^(NODE_THRIFT_GET_WITH_CONDITIONS columnFamily ^(CONDITIONS getCondition+)
^(NODE_LIMIT $limit)*) 
+    : GET columnFamilyExpr ('AS' typeIdentifier)? ('LIMIT' limit=IntegerLiteral)?
+        -> ^(NODE_THRIFT_GET columnFamilyExpr ( ^(CONVERT_TO_TYPE typeIdentifier) )? ^(NODE_LIMIT
$limit)?)
+    | GET columnFamily 'WHERE' getCondition ('AND' getCondition)* ('LIMIT' limit=IntegerLiteral)?
+        -> ^(NODE_THRIFT_GET_WITH_CONDITIONS columnFamily ^(CONDITIONS getCondition+)
^(NODE_LIMIT $limit)?) 
     ;
 
 getCondition

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java?rev=1124780&r1=1124779&r2=1124780&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java Thu
May 19 13:53:06 2011
@@ -306,7 +306,7 @@ public class CliClient extends CliUserHe
         sessionState.out.println(String.format("%s removed.", (columnSpecCnt == 0) ? "row"
: "column"));
     }
 
-    private void doSlice(String keyspace, ByteBuffer key, String columnFamily, byte[] superColumnName)
+    private void doSlice(String keyspace, ByteBuffer key, String columnFamily, byte[] superColumnName,
int limit)
             throws InvalidRequestException, UnavailableException, TimedOutException, TException,
IllegalAccessException, NotFoundException, InstantiationException, NoSuchFieldException
     {
         
@@ -314,7 +314,7 @@ public class CliClient extends CliUserHe
         if(superColumnName != null)
             parent.setSuper_column(superColumnName);
 
-        SliceRange range = new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER,
false, 1000000);
+        SliceRange range = new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER,
false, limit);
         List<ColumnOrSuperColumn> columns = thriftClient.get_slice(key, parent, new
SlicePredicate().setColumn_names(null).setSlice_range(range), consistencyLevel);
 
         AbstractType validator;
@@ -401,10 +401,39 @@ public class CliClient extends CliUserHe
         byte[] superColumnName = null;
         ByteBuffer columnName;
 
+        Tree typeTree = null;
+        Tree limitTree = null;
+
+        int limit = 1000000;
+
+        if (statement.getChildCount() >= 2)
+        {
+            if (statement.getChild(1).getType() == CliParser.CONVERT_TO_TYPE)
+            {
+                typeTree = statement.getChild(1).getChild(0);
+                if (statement.getChildCount() == 3)
+                    limitTree = statement.getChild(2).getChild(0);
+            }
+            else
+            {
+                limitTree = statement.getChild(1).getChild(0);
+            }
+        }
+
+        if (limitTree != null)
+        {
+            limit = Integer.parseInt(limitTree.getText());
+
+            if (limit == 0)
+            {
+                throw new IllegalArgumentException("LIMIT should be greater than zero.");
+            }
+        }
+
         // table.cf['key'] -- row slice
         if (columnSpecCnt == 0)
         {
-            doSlice(keySpace, key, columnFamily, superColumnName);
+            doSlice(keySpace, key, columnFamily, superColumnName, limit);
             return;
         }
         // table.cf['key']['column'] -- slice of a super, or get of a standard
@@ -415,7 +444,7 @@ public class CliClient extends CliUserHe
             if (isSuper)
             {
                 superColumnName = columnName.array();
-                doSlice(keySpace, key, columnFamily, superColumnName);
+                doSlice(keySpace, key, columnFamily, superColumnName, limit);
                 return;
             }
         }
@@ -433,7 +462,7 @@ 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);
@@ -451,14 +480,12 @@ public class CliClient extends CliUserHe
 
         byte[] columnValue = column.getValue();       
         String valueAsString;
-        
+
         // we have ^(CONVERT_TO_TYPE <type>) inside of GET statement
         // which means that we should try to represent byte[] value according
         // to specified type
-        if (statement.getChildCount() == 2)
+        if (typeTree != null)
         {
-            // getting ^(CONVERT_TO_TYPE <type>) tree 
-            Tree typeTree = statement.getChild(1).getChild(0);
             // .getText() will give us <type>
             String typeName = CliUtils.unescapeSQLString(typeTree.getText());
             // building AbstractType from <type>



Mime
View raw message