use of org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter in project drill by axbaretto.
the class TestVariableWidthWriter method testRestartRow.
@Test
public void testRestartRow() {
try (VarCharVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
VarCharColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
// Write rows, rewriting every other row.
String base = "sample-value";
writer.startRow();
index.index = 0;
for (int i = 0; i < 50; i++) {
writer.setString(base + i);
if (i % 2 == 0) {
writer.saveRow();
writer.startRow();
index.index++;
} else {
writer.restartRow();
}
}
writer.endWrite();
for (int i = 0; i < 25; i++) {
assertEquals(base + (2 * i), stringAt(vector, i));
}
}
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter in project drill by axbaretto.
the class TestVariableWidthWriter method makeWriter.
private VarCharColumnWriter makeWriter(VarCharVector vector, TestIndex index) {
VarCharColumnWriter writer = new VarCharColumnWriter(vector);
writer.bindIndex(index);
assertEquals(ValueType.STRING, writer.valueType());
return writer;
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter in project drill by axbaretto.
the class TestVariableWidthWriter method testWrite.
/**
* Basic test to write a contiguous set of values, enough to cause
* the vector to double in size twice, then read back the values.
*/
@Test
public void testWrite() {
try (VarCharVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
VarCharColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
// Write integers.
// Write enough that the vector is resized.
long origAddr = vector.getBuffer().addr();
String base = "sample-value";
for (int i = 0; i < 3000; i++) {
index.index = i;
writer.setString(base + i);
}
writer.endWrite();
// Should have been reallocated.
assertNotEquals(origAddr, vector.getBuffer().addr());
for (int i = 0; i < 3000; i++) {
assertEquals(base + i, stringAt(vector, i));
}
}
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter in project drill by axbaretto.
the class TestVariableWidthWriter method testRollover.
/**
* The rollover method is used during vector overflow.
*/
@Test
public void testRollover() {
try (VarCharVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
VarCharColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
// Simulate doing an overflow of ten values.
String base = "sample-value";
for (int i = 0; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setString(base + i);
writer.saveRow();
}
// Overflow occurs after writing the 11th row
index.index = 10;
writer.startRow();
String overflowValue = base + 10;
writer.setString(overflowValue);
// Overflow occurs
writer.preRollover();
// Simulate rollover
byte[] dummy = new byte[] { (byte) 0x55 };
for (int i = 0; i < 500; i++) {
vector.getMutator().setSafe(i, dummy);
}
for (int i = 1; i < 15; i++) {
vector.getOffsetVector().getMutator().set(i, 0xdeadbeef);
}
vector.getMutator().setSafe(0, overflowValue.getBytes(Charsets.UTF_8));
writer.postRollover();
index.index = 0;
writer.saveRow();
for (int i = 1; i < 5; i++) {
index.index = i;
writer.startRow();
writer.setString(base + (i + 10));
writer.saveRow();
}
writer.endWrite();
for (int i = 0; i < 5; i++) {
assertEquals(base + (10 + i), stringAt(vector, i));
}
}
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter in project drill by axbaretto.
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) {
// System.out.println("Delta: " + 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"));
}
}
}
Aggregations