cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r991580 - in /cassandra/trunk: interface/cassandra.genavro src/java/org/apache/cassandra/avro/CassandraServer.java test/system/test_avro_server.py
Date Wed, 01 Sep 2010 15:58:44 GMT
Author: eevans
Date: Wed Sep  1 15:58:44 2010
New Revision: 991580

URL: http://svn.apache.org/viewvc?rev=991580&view=rev
Log:
multiget_count implementation for avro

Patch by eevans

Modified:
    cassandra/trunk/interface/cassandra.genavro
    cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
    cassandra/trunk/test/system/test_avro_server.py

Modified: cassandra/trunk/interface/cassandra.genavro
URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.genavro?rev=991580&r1=991579&r2=991580&view=diff
==============================================================================
--- cassandra/trunk/interface/cassandra.genavro (original)
+++ cassandra/trunk/interface/cassandra.genavro Wed Sep  1 15:58:44 2010
@@ -136,6 +136,11 @@ protocol Cassandra {
          array<ColumnOrSuperColumn> columns;
     }
 
+    record KeyCountMapEntry {
+        bytes key;
+        int count;
+    }
+
     enum ConsistencyLevel {
         ZERO, ONE, QUORUM, DCQUORUM, DCQUORUMSYNC, ALL
     }
@@ -185,6 +190,16 @@ protocol Cassandra {
     throws InvalidRequestException, UnavailableException, TimedOutException;
 
     /**
+     * Performs a get_count in parallel on the given list of keys. The
+     * return value maps keys to the count found.
+     */ 
+    array<KeyCountMapEntry> multiget_count(array<bytes> keys,
+                                           ColumnParent column_parent,
+                                           SlicePredicate predicate,
+                                           ConsistencyLevel consistency_level)
+    throws InvalidRequestException, UnavailableException, TimedOutException;
+
+    /**
      * Returns the number of columns matching a predicate for a particular
      * key, ColumnFamily, and optionally SuperColumn.
      */

Modified: cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java?rev=991580&r1=991579&r2=991580&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java Wed Sep  1 15:58:44
2010
@@ -910,4 +910,28 @@ public class CassandraServer implements 
     {
         return StorageService.getPartitioner().getClass().getName();
     }
+
+    @Override
+    public List<KeyCountMapEntry> multiget_count(List<ByteBuffer> keys, ColumnParent
columnParent, SlicePredicate predicate, ConsistencyLevel consistencyLevel)
+    throws AvroRemoteException, InvalidRequestException, UnavailableException, TimedOutException
+    {
+        if (logger.isDebugEnabled())
+            logger.debug("multiget_count");
+        
+        checkKeyspaceAndLoginAuthorized(Permission.READ_VALUE);
+        String keyspace = clientState.getKeyspace();
+        
+        List<KeyCountMapEntry> counts = new ArrayList<KeyCountMapEntry>();
+        List<CoscsMapEntry> columnFamiliesMap = multigetSliceInternal(keyspace, keys,
columnParent, predicate, consistencyLevel);
+        
+        for (CoscsMapEntry cf : columnFamiliesMap)
+        {
+            KeyCountMapEntry countEntry = new KeyCountMapEntry();
+            countEntry.key = cf.key;
+            countEntry.count = cf.columns.size();
+            counts.add(countEntry);
+        }
+        
+        return counts;
+    }
 }

Modified: cassandra/trunk/test/system/test_avro_server.py
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_avro_server.py?rev=991580&r1=991579&r2=991580&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_avro_server.py (original)
+++ cassandra/trunk/test/system/test_avro_server.py Wed Sep  1 15:58:44 2010
@@ -379,6 +379,37 @@ class TestRpcOperations(AvroTester):
         assert 'NewColumnFamily' not in [x['name'] for x in ks1['cf_defs']]
         assert 'Standard1' in [x['name'] for x in ks1['cf_defs']]
 
+    def test_multiget_count(self):
+        "obtaining the column count for multiple rows"
+        self.__set_keyspace('Keyspace1')
+
+        mutations = list()
+
+        for i in range(10):
+            mutation = {'column_or_supercolumn': {'column': new_column(i)}}
+            mutations.append(mutation)
+
+        mutation_params = dict()
+        mutation_params['mutation_map'] = list()
+        for i in range(3):
+            entry = {'key': 'k'+str(i), 'mutations': {'Standard1': mutations}}
+            mutation_params['mutation_map'].append(entry)
+        mutation_params['consistency_level'] = 'ONE'
+
+        self.client.request('batch_mutate', mutation_params)
+
+        count_params = dict()
+        count_params['keys'] = ['k0', 'k1', 'k2']
+        count_params['column_parent'] = {'column_family': 'Standard1'}
+        sr = {'start': '', 'finish': '', 'reversed': False, 'count': 1000}
+        count_params['predicate'] = {'slice_range': sr}
+        count_params['consistency_level'] = 'ONE'
+
+        counts = self.client.request('multiget_count', count_params)
+        for e in counts:
+            assert(e['count'] == 10), \
+                "expected 10 results for %s, got %d" % (e['key'], e['count'])
+
     def __get(self, key, cf, super_name, col_name, consistency_level='ONE'):
         """
         Given arguments for the key, column family, super column name,



Mime
View raw message