Repository: cassandra
Updated Branches:
  refs/heads/trunk 754379507 -> 28cd76cd8


Handle Slices.NONE in sstable iterators

patch by jkni; reviewed by slebresne for CASSANDRA-11513


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/28cd76cd
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/28cd76cd
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/28cd76cd

Branch: refs/heads/trunk
Commit: 28cd76cd847eff0de851b250bf171ddd9bafb7fd
Parents: 7543795
Author: Joel Knighton <[email protected]>
Authored: Fri Apr 8 01:37:34 2016 -0500
Committer: Sylvain Lebresne <[email protected]>
Committed: Mon Apr 18 15:21:06 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../columniterator/AbstractSSTableIterator.java | 35 ++++++++++++++++--
 .../db/columniterator/SSTableIterator.java      |  2 +-
 .../columniterator/SSTableReversedIterator.java |  2 +-
 .../apache/cassandra/cql3/SimpleQueryTest.java  | 38 +++++++++++++++-----
 5 files changed, 65 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/28cd76cd/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 94f3c81..5cd20e3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.6
+ * Fix handling of empty slices (CASSANDRA-11513)
  * Make number of cores used by cqlsh COPY visible to testing code 
(CASSANDRA-11437)
  * Allow filtering on clustering columns for queries without secondary indexes 
(CASSANDRA-11310)
  * Refactor Restriction hierarchy (CASSANDRA-11354)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/28cd76cd/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java 
b/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java
index 7f2e3bb..296d142 100644
--- 
a/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java
+++ 
b/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.db.columniterator;
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.db.*;
@@ -113,7 +114,7 @@ abstract class AbstractSSTableIterator implements 
UnfilteredRowIterator
                     this.reader = needsReader ? createReader(indexEntry, file, 
shouldCloseFile) : null;
                 }
 
-                if (reader != null && slices.size() > 0)
+                if (reader != null && !slices.isEmpty())
                     reader.setForSlice(slices.get(0));
 
                 if (reader == null && file != null && shouldCloseFile)
@@ -187,7 +188,13 @@ abstract class AbstractSSTableIterator implements 
UnfilteredRowIterator
         }
     }
 
-    protected abstract Reader createReader(RowIndexEntry indexEntry, 
FileDataInput file, boolean shouldCloseFile);
+    protected abstract Reader createReaderInternal(RowIndexEntry indexEntry, 
FileDataInput file, boolean shouldCloseFile);
+
+    private Reader createReader(RowIndexEntry indexEntry, FileDataInput file, 
boolean shouldCloseFile)
+    {
+        return slices.isEmpty() ? new NoRowsReader(file, shouldCloseFile)
+                                : createReaderInternal(indexEntry, file, 
shouldCloseFile);
+    };
 
     public CFMetaData metadata()
     {
@@ -402,6 +409,30 @@ abstract class AbstractSSTableIterator implements 
UnfilteredRowIterator
         }
     }
 
+    // Reader for when we have Slices.NONE but need to read static row or 
partition level deletion
+    private class NoRowsReader extends AbstractSSTableIterator.Reader
+    {
+        private NoRowsReader(FileDataInput file, boolean shouldCloseFile)
+        {
+            super(file, shouldCloseFile);
+        }
+
+        public void setForSlice(Slice slice) throws IOException
+        {
+            return;
+        }
+
+        protected boolean hasNextInternal() throws IOException
+        {
+            return false;
+        }
+
+        protected Unfiltered nextInternal() throws IOException
+        {
+            throw new NoSuchElementException();
+        }
+    }
+
     // Used by indexed readers to store where they are of the index.
     protected static class IndexState
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/28cd76cd/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java 
b/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java
index 302fc24..354564a 100644
--- a/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java
+++ b/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java
@@ -42,7 +42,7 @@ public class SSTableIterator extends AbstractSSTableIterator
         super(sstable, file, key, indexEntry, slices, columns, isForThrift);
     }
 
-    protected Reader createReader(RowIndexEntry indexEntry, FileDataInput 
file, boolean shouldCloseFile)
+    protected Reader createReaderInternal(RowIndexEntry indexEntry, 
FileDataInput file, boolean shouldCloseFile)
     {
         return indexEntry.isIndexed()
              ? new ForwardIndexedReader(indexEntry, file, shouldCloseFile)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/28cd76cd/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java 
b/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java
index ba5acf5..d8b41b4 100644
--- 
a/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java
+++ 
b/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java
@@ -45,7 +45,7 @@ public class SSTableReversedIterator extends 
AbstractSSTableIterator
         super(sstable, file, key, indexEntry, slices, columns, isForThrift);
     }
 
-    protected Reader createReader(RowIndexEntry indexEntry, FileDataInput 
file, boolean shouldCloseFile)
+    protected Reader createReaderInternal(RowIndexEntry indexEntry, 
FileDataInput file, boolean shouldCloseFile)
     {
         return indexEntry.isIndexed()
              ? new ReverseIndexedReader(indexEntry, file, shouldCloseFile)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/28cd76cd/test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java 
b/test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java
index a46c750..22a4c49 100644
--- a/test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java
+++ b/test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java
@@ -392,24 +392,44 @@ public class SimpleQueryTest extends CQLTester
 
         execute("INSERT INTO %s (k, t, v, s) values (?, ?, ?, ?)", "key1", 3, 
"foo3", "st3");
         execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key1", 4, 
"foo4");
+        execute("INSERT INTO %s (k, t, v, s) values (?, ?, ?, ?)", "key1", 2, 
"foo2", "st2-repeat");
+
+        flush();
+
+        execute("INSERT INTO %s (k, t, v, s) values (?, ?, ?, ?)", "key1", 5, 
"foo5", "st5");
+        execute("INSERT INTO %s (k, t, v) values (?, ?, ?)", "key1", 6, 
"foo6");
+
 
         assertRows(execute("SELECT * FROM %s"),
-            row("key1",  1, "st3", "foo1"),
-            row("key1",  2, "st3", "foo2"),
-            row("key1",  3, "st3", "foo3"),
-            row("key1",  4, "st3", "foo4")
+            row("key1",  1, "st5", "foo1"),
+            row("key1",  2, "st5", "foo2"),
+            row("key1",  3, "st5", "foo3"),
+            row("key1",  4, "st5", "foo4"),
+            row("key1",  5, "st5", "foo5"),
+            row("key1",  6, "st5", "foo6")
         );
 
         assertRows(execute("SELECT s FROM %s WHERE k = ?", "key1"),
-            row("st3"),
-            row("st3"),
-            row("st3"),
-            row("st3")
+            row("st5"),
+            row("st5"),
+            row("st5"),
+            row("st5"),
+            row("st5"),
+            row("st5")
         );
 
         assertRows(execute("SELECT DISTINCT s FROM %s WHERE k = ?", "key1"),
-            row("st3")
+            row("st5")
         );
+
+        assertEmpty(execute("SELECT * FROM %s WHERE k = ? AND t > ? AND t < 
?", "key1", 7, 5));
+        assertEmpty(execute("SELECT * FROM %s WHERE k = ? AND t > ? AND t < ? 
ORDER BY t DESC", "key1", 7, 5));
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t = ?", "key1", 
2),
+            row("key1", 2, "st5", "foo2"));
+
+        assertRows(execute("SELECT * FROM %s WHERE k = ? AND t = ? ORDER BY t 
DESC", "key1", 2),
+            row("key1", 2, "st5", "foo2"));
     }
 
     @Test

Reply via email to