public class TestLoad extends ExecTest {
@Test
public void testLoadValueVector() throws Exception {
BufferAllocator allocator = new TopLevelAllocator();
ValueVector fixedV = new IntVector(MaterializedField.create(new SchemaPath("ints", ExpressionPosition.UNKNOWN),
Types.required(MinorType.INT)), allocator);
ValueVector varlenV = new VarCharVector(MaterializedField.create(
new SchemaPath("chars", ExpressionPosition.UNKNOWN), Types.required(MinorType.VARCHAR)), allocator);
ValueVector nullableVarlenV = new NullableVarCharVector(MaterializedField.create(new SchemaPath("chars",
ExpressionPosition.UNKNOWN), Types.optional(MinorType.VARCHAR)), allocator);
List<ValueVector> vectors = Lists.newArrayList(fixedV, varlenV, nullableVarlenV);
for (ValueVector v : vectors) {
AllocationHelper.allocate(v, 100, 50);
v.getMutator().generateTestData(100);
}
WritableBatch writableBatch = WritableBatch.getBatchNoHV(100, vectors, false);
RecordBatchLoader batchLoader = new RecordBatchLoader(allocator);
ByteBuf[] byteBufs = writableBatch.getBuffers();
int bytes = 0;
for (int i = 0; i < byteBufs.length; i++) {
bytes += byteBufs[i].writerIndex();
}
DrillBuf byteBuf = allocator.buffer(bytes);
int index = 0;
for (int i = 0; i < byteBufs.length; i++) {
byteBufs[i].readBytes(byteBuf, index, byteBufs[i].writerIndex());
index += byteBufs[i].writerIndex();
}