Author: brandonwilliams
Date: Wed Oct 12 16:25:00 2011
New Revision: 1182463

URL: http://svn.apache.org/viewvc?rev=1182463&view=rev
Log:
Skip empty rows when slicing the entire row.
Patch by Jeremy Hanna and brandonwilliams, reviewed by Jeremy Hanna for
CASSANDRA-2855

Modified:
    cassandra/branches/cassandra-0.8/CHANGES.txt
    
cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java

Modified: cassandra/branches/cassandra-0.8/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/CHANGES.txt?rev=1182463&r1=1182462&r2=1182463&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.8/CHANGES.txt Wed Oct 12 16:25:00 2011
@@ -4,6 +4,7 @@
  * (CQL) update grammar to require key clause in DELETE statement
    (CASSANDRA-3349)
  * (CQL) allow numeric keyspace names in USE statement (CASSANDRA-3350)
+ * (Hadoop) skip empty rows when slicing the entire row (CASSANDRA-2855)
 
 
 0.8.7

Modified: 
cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java?rev=1182463&r1=1182462&r2=1182463&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java
 (original)
+++ 
cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java
 Wed Oct 12 16:25:00 2011
@@ -98,7 +98,7 @@ public class ColumnFamilyRecordReader ex
         batchRowCount = ConfigHelper.getRangeBatchSize(conf);
         cfName = ConfigHelper.getInputColumnFamily(conf);
         consistencyLevel = 
ConsistencyLevel.valueOf(ConfigHelper.getReadConsistencyLevel(conf));
-        
+
         
         keyspace = ConfigHelper.getInputKeyspace(conf);
         
@@ -257,14 +257,24 @@ public class ColumnFamilyRecordReader ex
                     rows = null;
                     return;
                 }
-                               
-                // reset to iterate through this new batch
-                i = 0;
+
+                // Pre-compute the last row key, before removing empty rows
+                ByteBuffer lastRowKey = rows.get(rows.size() - 1).key;
+
+                // only remove empty rows if the slice predicate is empty
+                if (isPredicateEmpty(predicate))
+                {
+                    Iterator<KeySlice> rowsIterator = rows.iterator();
+                    while (rowsIterator.hasNext())
+                        if (rowsIterator.next().columns.isEmpty())
+                            rowsIterator.remove();
+                }
                 
+                // reset to iterate through the new batch
+                i = 0;
+
                 // prepare for the next slice to be read
-                KeySlice lastRow = rows.get(rows.size() - 1);
-                ByteBuffer rowkey = lastRow.key;
-                startToken = 
partitioner.getTokenFactory().toString(partitioner.getToken(rowkey));
+                startToken = 
partitioner.getTokenFactory().toString(partitioner.getToken(lastRowKey));
             }
             catch (Exception e)
             {
@@ -339,4 +349,16 @@ public class ColumnFamilyRecordReader ex
             return sc;
         }
     }
+
+    private boolean isPredicateEmpty(SlicePredicate predicate)
+    {
+        if (predicate != null)
+            if (predicate.isSetSlice_range())
+                if (predicate.getSlice_range().getStart() != null && 
predicate.getSlice_range().getFinish() != null)
+                return false;
+            else if (predicate.isSetColumn_names())
+                return false;
+
+        return true;
+    }
 }


Reply via email to