Skip to content

Commit

Permalink
Merge pull request #574 from mastersenthilkumar/master
Browse files Browse the repository at this point in the history
Fix for KeyIterator doesn't loop through all keys
  • Loading branch information
zznate committed Dec 29, 2012
2 parents 684cda8 + a9120c3 commit 570798c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class KeyIterator<K> implements Iterable<K> {
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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

}

0 comments on commit 570798c

Please sign in to comment.