use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter in project drill by axbaretto.
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();
OffsetVectorWriter 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.OffsetVectorWriter in project drill by axbaretto.
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();
OffsetVectorWriter 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));
}
}
}
use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter in project drill by axbaretto.
the class TestOffsetVectorWriter method testRolloverWithEmpties.
/**
* Simulate the case in which the tail end of an overflow
* batch has empties. <tt>preRollover()</tt> should back-fill
* them with the next offset prior to rollover.
*/
@Test
public void testRolloverWithEmpties() {
try (UInt4Vector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
OffsetVectorWriter 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();
}
for (int i = 10; i < 15; i++) {
index.index = i;
writer.startRow();
writer.saveRow();
}
// Overflow occurs before writing the 16th row
index.index = 15;
writer.startRow();
// Overflow occurs. This should fill empty offsets.
writer.preRollover();
for (int i = 0; i < 11; i++) {
assertEquals(i * 10, vector.getAccessor().get(i));
}
for (int i = 11; i < 16; i++) {
assertEquals("i = " + i, 100, vector.getAccessor().get(i));
}
for (int i = 0; i < 20; i++) {
vector.getMutator().set(i, 0xdeadbeef);
}
// Post rollover, slot 0 should be initialized.
// This is a rollover. This row must set the value
// for the new row 0 (which was presumably set/filled
// after the overflow.)
writer.postRollover();
index.index = 0;
writer.setNextOffset(0);
writer.saveRow();
for (int i = 1; i < 5; i++) {
index.index = i;
writer.startRow();
writer.saveRow();
}
for (int i = 5; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setNextOffset((i - 4) * 10);
writer.saveRow();
}
writer.endWrite();
for (int i = 0; i < 6; i++) {
assertEquals(0, vector.getAccessor().get(i));
}
for (int i = 6; i < 11; i++) {
assertEquals((i - 5) * 10, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter in project drill by axbaretto.
the class TestOffsetVectorWriter method testRestartRow.
@Test
public void testRestartRow() {
try (UInt4Vector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
OffsetVectorWriter writer = makeWriter(vector, index);
writer.startWrite();
// Write rows, rewriting every other row.
writer.startRow();
index.index = 0;
for (int i = 0; i < 50; i++) {
if (i % 2 == 0) {
assertEquals(i == 0 ? 0 : (i - 1) * 10, writer.nextOffset());
writer.setNextOffset((i + 1) * 10);
writer.saveRow();
writer.startRow();
index.index++;
} else {
writer.setNextOffset((i + 1) * 10);
writer.restartRow();
}
}
writer.endWrite();
// Verify values
assertEquals(0, vector.getAccessor().get(0));
for (int i = 1; i < 25; i++) {
assertEquals((2 * i - 1) * 10, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter in project drill by axbaretto.
the class TestOffsetVectorWriter method makeWriter.
private OffsetVectorWriter makeWriter(UInt4Vector vector, TestIndex index) {
OffsetVectorWriter writer = new OffsetVectorWriter(vector);
writer.bindIndex(index);
assertEquals(ValueType.INTEGER, writer.valueType());
return writer;
}
Aggregations