public class TestSplitAndTransfer {
@Test
public void test() throws Exception {
BufferAllocator allocator = new TopLevelAllocator();
MaterializedField field = MaterializedField.create("field", Types.optional(MinorType.VARCHAR));
NullableVarCharVector varCharVector = new NullableVarCharVector(field, allocator);
varCharVector.allocateNew(10000, 1000);
String[] compareArray = new String[500];
for (int i = 0; i < 500; i += 3) {
String s = String.format("%010d", i);
varCharVector.getMutator().set(i, s.getBytes());
compareArray[i] = s;
}
varCharVector.getMutator().setValueCount(500);
TransferPair tp = varCharVector.getTransferPair();
NullableVarCharVector newVarCharVector = (NullableVarCharVector) tp.getTo();
Accessor accessor = newVarCharVector.getAccessor();
int[][] startLengths = {{0, 201}, {201, 200}, {401, 99}};
for (int[] startLength : startLengths) {
int start = startLength[0];
int length = startLength[1];
tp.splitAndTransfer(start, length);
newVarCharVector.getMutator().setValueCount(length);
for (int i = 0; i < length; i++) {
boolean expectedSet = ((start + i) % 3) == 0;
if (expectedSet) {
byte[] expectedValue = compareArray[start + i].getBytes();
Assert.assertFalse(accessor.isNull(i));
// System.out.println(new String(accessor.get(i)));
Assert.assertArrayEquals(expectedValue, accessor.get(i));
} else {
Assert.assertTrue(accessor.isNull(i));
}
}
newVarCharVector.clear();
}
varCharVector.clear();
allocator.close();
}