use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter in project drill by axbaretto.
the class TestOffsetVectorWriter method testFillEmpties.
/**
* Offset vectors have specific behavior when back-filling missing values:
* the last offset must be carried forward into the missing slots. The
* slots cannot be zero-filled, or entries will end up with a negative
* length.
*/
@Test
public void testFillEmpties() {
try (UInt4Vector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
OffsetVectorWriter writer = makeWriter(vector, index);
writer.startWrite();
// Pretend to write offsets for values of width 10, but
// skip four out of five values, forcing backfill.
// The loop will cause the vector to double in size.
// The number of values is odd, forcing the writer to
// back-fill at the end as well as between values.
long origAddr = vector.getBuffer().addr();
for (int i = 5; i < 3001; i += 5) {
index.index = i;
writer.startRow();
int startOffset = writer.nextOffset();
assertEquals((i / 5 - 1) * 10, startOffset);
writer.setNextOffset(startOffset + 10);
writer.saveRow();
}
index.index = 3003;
writer.endWrite();
// Should have been reallocated.
assertNotEquals(origAddr, vector.getBuffer().addr());
for (int i = 0; i < 3004; i++) {
assertEquals(((i - 1) / 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 testSizeLimit.
/**
* Test resize monitoring. Add a listener to an offsets writer,
* capture each resize, and refuse a resize when the number
* of ints exceeds 8K values. This will trigger an overflow,
* which will throw an exception which we then check for.
*/
@Test
public void testSizeLimit() {
try (UInt4Vector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
OffsetVectorWriter writer = makeWriter(vector, index);
writer.bindListener(new ColumnWriterListener() {
int totalAlloc = 4096;
@Override
public void overflowed(ScalarWriter writer) {
throw new IllegalStateException("overflow called");
}
@Override
public boolean canExpand(ScalarWriter writer, int delta) {
// System.out.println("Delta: " + delta);
totalAlloc += delta;
return totalAlloc < 16_384 * 4;
}
});
writer.startWrite();
try {
for (int i = 0; ; i++) {
index.index = i;
writer.startRow();
writer.setNextOffset(i);
writer.saveRow();
}
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("overflow called"));
}
// Should have failed on 8191, which doubled vector
// to 16K, which was rejected. Note the 8191 value,
// because offsets are one ahead of the index.
assertEquals(8191, index.index);
}
}
Aggregations