Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix for KeyIterator doesn't loop through all keys when maxRowCount is…

… given as 1
  • Loading branch information...
commit a9120c3a43835e56ba987dc47173dc37943ae9db 1 parent b21dcb7
@skaruppiah skaruppiah authored
View
8 core/src/main/java/me/prettyprint/cassandra/service/KeyIterator.java
@@ -35,6 +35,7 @@
private K lastReadValue = null;
private K endKey;
private boolean firstRun = true;
+ private int rowCount = MAX_ROW_COUNT_DEFAULT;
private Iterator<K> keyIterator = new Iterator<K>() {
@Override
@@ -99,12 +100,17 @@ public KeyIterator(Keyspace keyspace, String columnFamily, Serializer<K> seriali
.setRowCount(maxRowCount);
endKey = end;
+ if(maxRowCount < Integer.MAX_VALUE) {
+ rowCount = maxRowCount+1; //to compensate the first entry skip (except in first run)
+ }
runQuery(start, end);
}
private void runQuery(K start, K end) {
query.setKeys(start, end);
-
+ if(!firstRun) {
+ query.setRowCount(rowCount);
+ }
rowsIterator = null;
QueryResult<OrderedRows<K, String, String>> result = query.execute();
OrderedRows<K, String, String> rows = (result != null) ? result.get() : null;
View
16 core/src/test/java/me/prettyprint/cassandra/service/KeyIteratorTest.java
@@ -54,6 +54,12 @@ public void testIterator() {
assertStringKeys(5, "k5", null);
assertStringKeys(9, null, null);
assertStringKeys(7, null, "k7");
+
+ assertKeys(5, "k5", 1);
+ assertKeys(9, null, 2);
+ assertKeys(9, null, 5);
+ assertKeys(8, "k2", 7);
+ assertKeys(7, "k3", 10);
}
private void assertKeys(int expected, String start, String end) {
@@ -76,4 +82,14 @@ private void assertStringKeys(int expected, String start, String end) {
assertEquals(expected, tot);
}
+ private void assertKeys(int expected, String start, int count) {
+ Iterable<String> it = new KeyIterator.Builder<String>(keyspace, CF, se).start(start).maxRowCount(count).build();
+
+ int tot = 0;
+ for (String key : it)
+ tot++;
+
+ assertEquals(expected, tot);
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.