I wanted a program to display Row Id values in the simplest way
possible. Please let me know if I have overlooked something. First, i
wrapped the RowIterator like this;
package com.codebits.accumulo;
import java.util.Iterator;
import java.util.Map.Entry;
import org.apache.accumulo.core.client.RowIterator;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Value;
public class RowIdIterator implements Iterator<String>, Iterable<String> {
Scanner scanner = null;
RowIterator iterator = null;
public RowIdIterator(Scanner scanner) {
super();
this.scanner = scanner;
this.iterator = new RowIterator(scanner);
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public String next() {
Iterator<Entry<Key, Value>> entry = iterator.next();
return entry.next().getKey().getRow().toString();
}
@Override
public void remove() {
}
@Override
public Iterator<String> iterator() {
return this;
}
}
And then I used a driver program like this;
package com.codebits.accumulo;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.ZooKeeperInstance;
import org.apache.accumulo.core.security.Authorizations;
public class RowIdInteratorDriver {
public static void main(String[] args) throws AccumuloException,
AccumuloSecurityException, TableNotFoundException {
String instanceName = "development";
String zooKeepers = "localhost";
String user = "root";
byte[] pass = "password".getBytes();
String tableName = "test_row_iterator";
Authorizations authorizations = new Authorizations();
ZooKeeperInstance instance = new
ZooKeeperInstance(instanceName, zooKeepers);
Connector connector = instance.getConnector(user, pass);
Scanner scanner = connector.createScanner(tableName, authorizations);
for (String rowId : new RowIdIterator(scanner)) {
System.out.println("ROW ID: " + rowId);
}
}
}
This code works:
ROW ID: R001
ROW ID: R002
ROW ID: R003
My concern is that scanner that I am passing into the iterator. How is
that testable? And, of course, the class name is confusing..