public void testRowScannerSparseData() throws Exception {
final KijiTable table = mKiji.openTable("users");
try {
// Reuse these entity IDs for puts and for gets.
final EntityId alice = table.getEntityId("Alice");
final EntityId bob = table.getEntityId("Bob");
final EntityId cathy = table.getEntityId("Cathy");
final EntityId david = table.getEntityId("David");
final String pets = "pets";
final String cat = "cat";
final String dog = "dog";
final String rabbit = "rabbit";
final String fish = "fish";
final String bird = "bird";
final KijiTableWriter writer = table.openTableWriter();
try {
// Insert some data into the table. Give various users different pets.
writer.put(alice, pets, cat, 0L, "Alister");
writer.put(bob, pets, cat, 0L, "Buffy");
writer.put(cathy, pets, cat, 0L, "Mr Cat");
writer.put(david, pets, cat, 0L, "Dash");
writer.put(alice, pets, dog, 0L, "Amour");
writer.put(bob, pets, rabbit, 0L, "Bounce");
writer.put(cathy, pets, fish, 0L, "Catfish");
writer.put(david, pets, bird, 0L, "Da Bird");
} finally {
writer.close();
}
final KijiDataRequest dataRequest = KijiDataRequest.builder()
.addColumns(
ColumnsDef
.create()
.withMaxVersions(100)
.add(pets, cat)
.add(pets, dog)
.add(pets, rabbit)
.add(pets, fish)
.add(pets, bird)
).build();
final KijiTableReader reader = table.openTableReader();
try {
// Fire up a row scanner!
final KijiRowScanner scanner = reader.getScanner(dataRequest);
try {
// There is a small enough amount of data that we can just put all of the rows into a hash
// from entity ID to row data.
HashMap<EntityId, KijiRowData> allData = new HashMap<EntityId, KijiRowData>();
for (KijiRowData row : scanner) {
EntityId eid = row.getEntityId();
assert (!allData.containsKey(eid));
allData.put(eid, row);
}
assertTrue(allData.containsKey(alice));