use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriterImpl in project drill by apache.
the class TestOffsetVectorWriter method testWrite.
/**
* Basic test to write a contiguous set of offsets, enough to cause
* the vector to double in size twice, then read back the values.
*/
@Test
public void testWrite() {
try (UInt4Vector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
OffsetVectorWriterImpl writer = makeWriter(vector, index);
// Start write sets initial position to 0.
writer.startWrite();
assertEquals(0, vector.getAccessor().get(0));
// Pretend to write offsets for values of width 10. We write
// the end position of each field.
// Write enough that the vector is resized.
long origAddr = vector.getBuffer().addr();
for (int i = 0; i < 3000; i++) {
index.index = i;
writer.startRow();
assertEquals(i * 10, writer.nextOffset());
writer.setNextOffset((i + 1) * 10);
assertEquals((i + 1) * 10, writer.nextOffset());
writer.saveRow();
}
writer.endWrite();
// Should have been reallocated.
assertNotEquals(origAddr, vector.getBuffer().addr());
for (int i = 0; i < 3001; i++) {
assertEquals(i * 10, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriterImpl in project drill by apache.
the class TestOffsetVectorWriter method testRollover.
/**
* The rollover method is used during vector overflow.
*/
@Test
public void testRollover() {
try (UInt4Vector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
OffsetVectorWriterImpl writer = makeWriter(vector, index);
writer.startWrite();
for (int i = 0; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setNextOffset((i + 1) * 10);
writer.saveRow();
}
// Overflow occurs after writing the 11th row
index.index = 10;
writer.startRow();
writer.setNextOffset(110);
// Overflow occurs
writer.preRollover();
for (int i = 0; i < 15; i++) {
vector.getMutator().set(i, 0xdeadbeef);
}
// Simulate shifting the last value down (which changes
// the offset.)
vector.getMutator().set(1, 10);
// Post rollover, slot 0 should be initialized
writer.postRollover();
index.index = 0;
writer.saveRow();
for (int i = 1; i < 5; i++) {
index.index = i;
writer.startRow();
writer.setNextOffset((i + 1) * 10);
writer.saveRow();
}
writer.endWrite();
for (int i = 0; i < 6; i++) {
assertEquals(i * 10, vector.getAccessor().get(i));
}
}
}
Aggregations