cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r802978 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java src/java/org/apache/cassandra/db/marshal/AbstractType.java test/system/test_server.py
Date Tue, 11 Aug 2009 02:09:41 GMT
Author: jbellis
Date: Tue Aug 11 02:09:40 2009
New Revision: 802978

URL: http://svn.apache.org/viewvc?rev=802978&view=rev
Log:
respect "start" filter argument for subcolumns.
patch by jbellis; reviewed by Even Weaver for CASSANDRA-357

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java
    incubator/cassandra/trunk/test/system/test_server.py

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java?rev=802978&r1=802977&r2=802978&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
Tue Aug 11 02:09:40 2009
@@ -8,6 +8,7 @@
 
 import org.apache.commons.collections.comparators.ReverseComparator;
 import org.apache.commons.collections.iterators.ReverseListIterator;
+import org.apache.commons.collections.IteratorUtils;
 
 import org.apache.cassandra.io.SSTableReader;
 import org.apache.cassandra.db.*;
@@ -51,6 +52,19 @@
         {
             subcolumns = superColumn.getSubColumns().iterator();
         }
+
+        // iterate until we get to the "real" start column
+        Comparator<byte[]> comparator = reversed ? superColumn.getComparator().getReverseComparator()
: superColumn.getComparator();
+        while (subcolumns.hasNext())
+        {
+            IColumn column = subcolumns.next();
+            if (comparator.compare(column.name(), start) >= 0)
+            {
+                subcolumns = IteratorUtils.chainedIterator(IteratorUtils.singletonIterator(column),
subcolumns);
+                break;
+            }
+        }
+        // subcolumns is either empty now, or has been redefined in the loop above.  either
is ok.
         collectReducedColumns(scFiltered, subcolumns, gcBefore);
         return scFiltered;
     }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java?rev=802978&r1=802977&r2=802978&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java Tue
Aug 11 02:09:40 2009
@@ -24,6 +24,26 @@
         getString(bytes);
     }
 
+    public Comparator<byte[]> getReverseComparator()
+    {
+        return new Comparator<byte[]>()
+        {
+            public int compare(byte[] o1, byte[] o2)
+            {
+                if (o1.length == 0)
+                {
+                    return o2.length == 0 ? 0 : -1;
+                }
+                if (o2.length == 0)
+                {
+                    return 1;
+                }
+
+                return -AbstractType.this.compare(o1, o2);
+            }
+        };
+    }
+
     /** convenience method */
     public String getString(Collection<byte[]> names)
     {

Modified: incubator/cassandra/trunk/test/system/test_server.py
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/system/test_server.py?rev=802978&r1=802977&r2=802978&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/system/test_server.py (original)
+++ incubator/cassandra/trunk/test/system/test_server.py Tue Aug 11 02:09:40 2009
@@ -187,17 +187,39 @@
             L.append(uuid.uuid1())
             client.insert('Keyspace2', 'key1', ColumnPath('Super4', 'sc1', L[-1].bytes),
'value%s' % i, i, ConsistencyLevel.ONE)
         slice = _big_slice('Keyspace2', 'key1', ColumnParent('Super4', 'sc1'))
-        assert len(slice) == 500
+        assert len(slice) == 500, len(slice)
         for i in xrange(500):
             u = slice[i].column
             assert u.value == 'value%s' % i
             assert u.name == L[i].bytes
 
-        p = SlicePredicate(slice_range=SliceRange('', '', False, 1))
+        p = SlicePredicate(slice_range=SliceRange('', '', True, 1))
         column_parent = ColumnParent('Super4', 'sc1')
         slice = [result.column
                  for result in client.get_slice('Keyspace2', 'key1', column_parent, p, ConsistencyLevel.ONE)]
         assert slice == [Column(L[-1].bytes, 'value499', 499)], slice
+
+        p = SlicePredicate(slice_range=SliceRange('', L[2].bytes, False, 1000))
+        column_parent = ColumnParent('Super4', 'sc1')
+        slice = [result.column
+                 for result in client.get_slice('Keyspace2', 'key1', column_parent, p, ConsistencyLevel.ONE)]
+        assert slice == [Column(L[0].bytes, 'value0', 0),
+                         Column(L[1].bytes, 'value1', 1),
+                         Column(L[2].bytes, 'value2', 2)], slice
+
+        p = SlicePredicate(slice_range=SliceRange(L[2].bytes, '', True, 1000))
+        column_parent = ColumnParent('Super4', 'sc1')
+        slice = [result.column
+                 for result in client.get_slice('Keyspace2', 'key1', column_parent, p, ConsistencyLevel.ONE)]
+        assert slice == [Column(L[2].bytes, 'value2', 2),
+                         Column(L[1].bytes, 'value1', 1),
+                         Column(L[0].bytes, 'value0', 0)], slice
+
+        p = SlicePredicate(slice_range=SliceRange(L[2].bytes, '', False, 1))
+        column_parent = ColumnParent('Super4', 'sc1')
+        slice = [result.column
+                 for result in client.get_slice('Keyspace2', 'key1', column_parent, p, ConsistencyLevel.ONE)]
+        assert slice == [Column(L[2].bytes, 'value2', 2)], slice
         
     def test_batch_insert(self):
         _insert_batch(False)



Mime
View raw message