cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r981541 - /cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
Date Mon, 02 Aug 2010 15:05:11 GMT
Author: jbellis
Date: Mon Aug  2 15:05:11 2010
New Revision: 981541

URL: http://svn.apache.org/viewvc?rev=981541&view=rev
Log:
make ColumnGroupReader implement Iterator<IColumn>
patch by jbellis; reviewed by gdusbabek for CASSANDRA-1338

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java?rev=981541&r1=981540&r2=981541&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java Mon
Aug  2 15:05:11 2010
@@ -41,13 +41,13 @@ import org.apache.cassandra.utils.FBUtil
 /**
  *  A Column Iterator over SSTable
  */
-class SSTableSliceIterator extends AbstractIterator<IColumn> implements IColumnIterator
+class SSTableSliceIterator implements IColumnIterator
 {
     private final boolean reversed;
     private final byte[] startColumn;
     private final byte[] finishColumn;
     private final AbstractType comparator;
-    private ColumnGroupReader reader;
+    private IColumnIterator reader;
     private boolean closeFileWhenDone = false;
     private DecoratedKey decoratedKey;
 
@@ -105,42 +105,24 @@ class SSTableSliceIterator extends Abstr
         return decoratedKey;
     }
 
-    private boolean isColumnNeeded(IColumn column)
+    public ColumnFamily getColumnFamily() throws IOException
     {
-        if (startColumn.length == 0 && finishColumn.length == 0)
-            return true;
-        else if (startColumn.length == 0 && !reversed)
-            return comparator.compare(column.name(), finishColumn) <= 0;
-        else if (startColumn.length == 0 && reversed)
-            return comparator.compare(column.name(), finishColumn) >= 0;
-        else if (finishColumn.length == 0 && !reversed)
-            return comparator.compare(column.name(), startColumn) >= 0;
-        else if (finishColumn.length == 0 && reversed)
-            return comparator.compare(column.name(), startColumn) <= 0;
-        else if (!reversed)
-            return comparator.compare(column.name(), startColumn) >= 0 && comparator.compare(column.name(),
finishColumn) <= 0;
-        else // if reversed
-            return comparator.compare(column.name(), startColumn) <= 0 && comparator.compare(column.name(),
finishColumn) >= 0;
+        return reader == null ? null : reader.getColumnFamily();
     }
 
-    public ColumnFamily getColumnFamily()
+    public boolean hasNext()
     {
-        return reader == null ? null : reader.getEmptyColumnFamily();
+        return reader.hasNext();
     }
 
-    protected IColumn computeNext()
+    public IColumn next()
     {
-        if (reader == null)
-            return endOfData();
+        return reader.next();
+    }
 
-        while (true)
-        {
-            IColumn column = reader.pollColumn();
-            if (column == null)
-                return endOfData();
-            if (isColumnNeeded(column))
-                return column;
-        }
+    public void remove()
+    {
+        throw new UnsupportedOperationException();
     }
 
     public void close() throws IOException
@@ -154,7 +136,7 @@ class SSTableSliceIterator extends Abstr
      *  blocks before/after it for each next call. This function assumes that
      *  the CF is sorted by name and exploits the name index.
      */
-    class ColumnGroupReader
+    class ColumnGroupReader extends AbstractIterator<IColumn> implements IColumnIterator
     {
         private final ColumnFamily emptyColumnFamily;
 
@@ -186,27 +168,51 @@ class SSTableSliceIterator extends Abstr
                 curRangeIndex--;
         }
 
-        public ColumnFamily getEmptyColumnFamily()
+        public ColumnFamily getColumnFamily()
         {
             return emptyColumnFamily;
         }
 
-        public IColumn pollColumn()
+        public DecoratedKey getKey()
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        private boolean isColumnNeeded(IColumn column)
+        {
+            if (startColumn.length == 0 && finishColumn.length == 0)
+                return true;
+            else if (startColumn.length == 0 && !reversed)
+                return comparator.compare(column.name(), finishColumn) <= 0;
+            else if (startColumn.length == 0 && reversed)
+                return comparator.compare(column.name(), finishColumn) >= 0;
+            else if (finishColumn.length == 0 && !reversed)
+                return comparator.compare(column.name(), startColumn) >= 0;
+            else if (finishColumn.length == 0 && reversed)
+                return comparator.compare(column.name(), startColumn) <= 0;
+            else if (!reversed)
+                return comparator.compare(column.name(), startColumn) >= 0 &&
comparator.compare(column.name(), finishColumn) <= 0;
+            else // if reversed
+                return comparator.compare(column.name(), startColumn) <= 0 &&
comparator.compare(column.name(), finishColumn) >= 0;
+        }
+
+        protected IColumn computeNext()
         {
-            IColumn column = blockColumns.poll();
-            if (column == null)
+            while (true)
             {
+                IColumn column = blockColumns.poll();
+                if (column != null && isColumnNeeded(column))
+                    return column;
                 try
                 {
-                    if (getNextBlock())
-                        column = blockColumns.poll();
+                    if (column == null && !getNextBlock())
+                        return endOfData();
                 }
                 catch (IOException e)
                 {
                     throw new RuntimeException(e);
                 }
             }
-            return column;
         }
 
         public boolean getNextBlock() throws IOException



Mime
View raw message