ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
// TODO: add map field later
reader.setProjection("c.f14, f1, r.f11, XYZ");
Tuple row = TypesUtils.createTuple(reader.getSchema());
TableScanner scanner = reader.getScanner(null, false);
BytesWritable key = new BytesWritable();
scanner.getKey(key);
Assert.assertEquals(key, new BytesWritable("k1".getBytes()));
scanner.getValue(row);
DataBag bagColl = (DataBag) row.get(0);
Iterator<Tuple> itorColl = bagColl.iterator();
Tuple tupColl = itorColl.next();
Assert.assertEquals(1.6, tupColl.get(0));
// make sure only 1 element returned in the collection
try {
Object obj = tupColl.get(1);
Assert.fail("Failed to catch 'out of boundary' exceptions.");
} catch (IndexOutOfBoundsException e) {
// no op, expecting out of bounds exceptions
}
tupColl = itorColl.next();
Assert.assertEquals(100, tupColl.get(0));
try {
Object obj = tupColl.get(1);
Assert.fail("Failed to catch 'out of boundary' exceptions.");
} catch (IndexOutOfBoundsException e) {
// no op, expecting out of bounds exceptions
}
Assert.assertFalse(itorColl.hasNext());
Assert.assertEquals(true, row.get(1));
Assert.assertEquals(1, row.get(2));
Assert.assertNull(row.get(3));
try {
Object obj = row.get(4);
Assert.fail("Failed to catch 'out of boundary' exceptions.");
} catch (IndexOutOfBoundsException e) {
// no op, expecting out of bounds exceptions
}
scanner.advance();
scanner.getKey(key);
Assert.assertEquals(key, new BytesWritable("k2".getBytes()));
TypesUtils.resetTuple(row);
scanner.getValue(row);
bagColl.clear();
bagColl = (DataBag) row.get(0);
itorColl = bagColl.iterator();
tupColl = itorColl.next();
Assert.assertEquals(0.0001, tupColl.get(0));
tupColl = itorColl.next();
Assert.assertEquals(0.3333, tupColl.get(0));
Assert.assertEquals(false, row.get(1));
Assert.assertEquals(2, row.get(2));
Assert.assertNull(row.get(3));
scanner.close();
reader.close();
}