cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r799632 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/db/filter/ src/java/org/apache/cassandra/io/ test/unit/org/apache/cassandra/db/
Date Fri, 31 Jul 2009 15:06:35 GMT
Author: jbellis
Date: Fri Jul 31 15:06:35 2009
New Revision: 799632

URL: http://svn.apache.org/viewvc?rev=799632&view=rev
Log:
allow start of [] to mean "start with the largest value" when ascending=false.  patch by Jun
Rao; reviewed by jbellis for CASSANDRA-263

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java?rev=799632&r1=799631&r2=799632&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java Fri Jul 31 15:06:35
2009
@@ -278,7 +278,16 @@
         // can't use a ColumnComparatorFactory comparator since those compare on both name
and time (and thus will fail to match
         // our dummy column, since the time there is arbitrary).
         Comparator<IColumn> comparator = filter.getColumnComparator(typeComparator);
-        int index = Arrays.binarySearch(columns, startIColumn, comparator);
+        int index;
+        if (filter.start.length == 0 && !filter.isAscending)
+        {
+            /* assuming the we scan from the largest column in descending order*/
+            index = 0;
+        }
+        else
+        {
+            index = Arrays.binarySearch(columns, startIColumn, comparator);
+        }
         final int startIndex = index < 0 ? -(index + 1) : index;
 
         return new AbstractColumnIterator()

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java?rev=799632&r1=799631&r2=799632&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
Fri Jul 31 15:06:35 2009
@@ -41,9 +41,21 @@
     private boolean isColumnNeeded(IColumn column)
     {
         if (isAscending)
+        {
             return comparator.compare(column.name(), startColumn) >= 0;
+        }
         else
-            return comparator.compare(column.name(), startColumn) <= 0;
+        {
+            if (startColumn.length == 0)
+            {
+                /* assuming scanning from the largest column in descending order */
+                return true;
+            }
+            else
+            {
+                return comparator.compare(column.name(), startColumn) <= 0;
+            }
+        }
     }
 
     private void getColumnsFromBuffer() throws IOException

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=799632&r1=799631&r2=799632&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
Fri Jul 31 15:06:35 2009
@@ -42,8 +42,12 @@
 
         for (IColumn column : superColumn.getSubColumns())
         {
-            if ((start.length > 0 && superColumn.getComparator().compare(column.name(),
start) < 0)
-                || (finish.length > 0 && superColumn.getComparator().compare(column.name(),
finish) > 0)
+            final boolean outOfRange = isAscending
+                                     ? (start.length > 0 && superColumn.getComparator().compare(column.name(),
start) < 0)
+                                        || (finish.length > 0 && superColumn.getComparator().compare(column.name(),
finish) > 0)
+                                     : (start.length > 0 && superColumn.getComparator().compare(column.name(),
start) > 0)
+                                        || (finish.length > 0 && superColumn.getComparator().compare(column.name(),
finish) < 0);
+            if (outOfRange
                 || (column.isMarkedForDelete() && column.getLocalDeletionTime() <=
gcBefore)
                 || liveColumns > count)
             {

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java?rev=799632&r1=799631&r2=799632&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java Fri Jul 31
15:06:35 2009
@@ -141,8 +141,16 @@
                 columnStartPosition_ = file_.getFilePointer();
                 columnIndexList_ = getFullColumnIndexList(colIndexList, totalNumCols);
 
-                int index = Collections.binarySearch(columnIndexList_, new IndexHelper.ColumnIndexInfo(startColumn,
0, 0, comparator_));
-                curRangeIndex_ = index < 0 ? (++index) * (-1) - 1 : index;
+                if (startColumn.length == 0 && !isAscending_)
+                {
+                    /* in this case, we assume that we want to scan from the largest column
in descending order. */
+                    curRangeIndex_ = columnIndexList_.size() - 1;
+                }
+                else
+                {
+                    int index = Collections.binarySearch(columnIndexList_, new IndexHelper.ColumnIndexInfo(startColumn,
0, 0, comparator_));
+                    curRangeIndex_ = index < 0 ? (++index) * (-1) - 1 : index;
+                }
             }
             else
             {

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java?rev=799632&r1=799631&r2=799632&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java Fri Jul 31
15:06:35 2009
@@ -210,6 +210,9 @@
                 cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col6".getBytes(),
ArrayUtils.EMPTY_BYTE_ARRAY, false, 2);
                 assertColumns(cf, "col3", "col4", "col5");
 
+                cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ArrayUtils.EMPTY_BYTE_ARRAY,
ArrayUtils.EMPTY_BYTE_ARRAY, false, 2);
+                assertColumns(cf, "col7", "col9");
+
                 cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), "col95".getBytes(),
ArrayUtils.EMPTY_BYTE_ARRAY, true, 2);
                 assertColumns(cf);
 
@@ -309,6 +312,12 @@
         assertEquals(new String(cf.getColumn("col1990".getBytes()).value()), "vvvvvvvvvvvvvvvv1990");
         assertEquals(new String(cf.getColumn("col1991".getBytes()).value()), "vvvvvvvvvvvvvvvv1991");
         assertEquals(new String(cf.getColumn("col1992".getBytes()).value()), "vvvvvvvvvvvvvvvv1992");
+
+        cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ArrayUtils.EMPTY_BYTE_ARRAY,
ArrayUtils.EMPTY_BYTE_ARRAY, false, 3);
+        assertColumns(cf, "col1997", "col1998", "col1999");
+        assertEquals(new String(cf.getColumn("col1999".getBytes()).value()), "vvvvvvvvvvvvvvvv1999");
+        assertEquals(new String(cf.getColumn("col1998".getBytes()).value()), "vvvvvvvvvvvvvvvv1998");
+        assertEquals(new String(cf.getColumn("col1997".getBytes()).value()), "vvvvvvvvvvvvvvvv1997");
     }
 
     @Test



Mime
View raw message