use of org.apache.drill.exec.vector.accessor.writer.WriterEvents.ColumnWriterListener in project drill by apache.
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();
OffsetVectorWriterImpl 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) {
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);
}
}
use of org.apache.drill.exec.vector.accessor.writer.WriterEvents.ColumnWriterListener in project drill by apache.
the class TestVariableWidthWriter method testSizeLimit.
/**
* Test resize monitoring. Add a listener to an Varchar writer,
* capture each resize, and refuse a resize when the s
* of the vector exceeds 1 MB. This will trigger an overflow,
* which will throw an exception which we then check for.
*/
@Test
public void testSizeLimit() {
try (VarCharVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
VarCharColumnWriter writer = makeWriter(vector, index);
writer.bindListener(new ColumnWriterListener() {
// Because assumed array size is 10, so 10 * 1000 = 10,000
// rounded to 16K
int totalAlloc = 16384;
@Override
public void overflowed(ScalarWriter writer) {
throw new IllegalStateException("overflow called");
}
@Override
public boolean canExpand(ScalarWriter writer, int delta) {
totalAlloc += delta;
return totalAlloc < 1024 * 1024;
}
});
writer.startWrite();
byte[] value = new byte[423];
Arrays.fill(value, (byte) 'X');
try {
for (int i = 0; ; i++) {
index.index = i;
writer.startRow();
writer.setBytes(value, value.length);
writer.saveRow();
}
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("overflow called"));
}
}
}
use of org.apache.drill.exec.vector.accessor.writer.WriterEvents.ColumnWriterListener in project drill by apache.
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) {
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);
}
}
Aggregations