use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by apache.
the class TestFixedWidthWriter method makeWriter.
private IntColumnWriter makeWriter(IntVector vector, TestIndex index) {
IntColumnWriter writer = new IntColumnWriter(vector);
writer.bindIndex(index);
assertEquals(ValueType.INTEGER, writer.valueType());
return writer;
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by axbaretto.
the class TestFixedWidthWriter method testSizeLimit.
/**
* Test resize monitoring. Add a listener to an int 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 (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter 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.setInt(i);
writer.saveRow();
}
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("overflow called"));
}
// Should have failed on 8192, which doubled vector
// to 16K, which was rejected.
assertEquals(8192, index.index);
}
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by axbaretto.
the class TestFixedWidthWriter method testFillEmpties.
/**
* Required, fixed-width vectors are back-filling with 0 to fill in missing
* values. While using zero is not strictly SQL compliant, it is better
* than failing. (The SQL solution would be to fill with nulls, but a
* required vector does not support nulls...)
*/
@Test
public void testFillEmpties() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
for (int i = 0; i < 501; i += 5) {
index.index = i;
writer.startRow();
writer.setInt(i);
writer.saveRow();
}
// At end, vector index defined to point one past the
// last row. That is, the vector index gives the row count.
index.index = 504;
writer.endWrite();
for (int i = 0; i < 504; i++) {
assertEquals("Mismatch on " + i, (i % 5) == 0 ? i : 0, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by axbaretto.
the class TestFixedWidthWriter method testSkipNulls.
/**
* Test the case in which a scalar vector is used in conjunction
* with a nullable bits vector. The nullable vector will call the
* <tt>skipNulls()</tt> method to avoid writing values for null
* entries. (Without the call, the scalar writer will fill the
* empty values with zeros.)
*/
@Test
public void testSkipNulls() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
// Write values, skipping four out of five positions,
// skipping nulls.
// The loop will cause the vector to double in size.
// The number of values is odd, forcing the writer to
// skip nulls at the end as well as between values.
long origAddr = vector.getBuffer().addr();
for (int i = 0; i < 3000; i += 5) {
index.index = i;
writer.startRow();
writer.skipNulls();
writer.setInt(i);
writer.saveRow();
}
index.index = 3003;
writer.startRow();
writer.skipNulls();
writer.saveRow();
writer.endWrite();
// Should have been reallocated.
assertNotEquals(origAddr, vector.getBuffer().addr());
for (int i = 0; i < 1000; i++) {
assertEquals("Mismatch at " + i, (i % 5) == 0 ? i : 0xdeadbeef, vector.getAccessor().get(i));
}
for (int i = 1005; i < 3000; i += 5) {
assertEquals(i, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by axbaretto.
the class TestFixedWidthWriter method makeWriter.
private IntColumnWriter makeWriter(IntVector vector, TestIndex index) {
IntColumnWriter writer = new IntColumnWriter(vector);
writer.bindIndex(index);
assertEquals(ValueType.INTEGER, writer.valueType());
return writer;
}
Aggregations