use of io.netty.buffer.DrillBuf in project drill by axbaretto.
the class TestValueVector method testNullableVarCharVectorLoad.
@Test
public void testNullableVarCharVectorLoad() {
final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVarCharHolder.TYPE);
// Create a new value vector for 1024 nullable variable length strings.
@SuppressWarnings("resource") final NullableVarCharVector vector1 = new NullableVarCharVector(field, allocator);
final NullableVarCharVector.Mutator mutator = vector1.getMutator();
vector1.allocateNew(1024 * 10, 1024);
// Populate the vector.
final StringBuilder stringBuilder = new StringBuilder();
final int valueCount = 10;
for (int i = 0; i < valueCount; ++i) {
stringBuilder.append('x');
mutator.set(i, stringBuilder.toString().getBytes(utf8Charset));
}
// Check the contents.
final NullableVarCharVector.Accessor accessor1 = vector1.getAccessor();
stringBuilder.setLength(0);
for (int i = 0; i < valueCount; ++i) {
stringBuilder.append('x');
final Object object = accessor1.getObject(i);
assertEquals(stringBuilder.toString(), object.toString());
}
mutator.setValueCount(valueCount);
assertEquals(valueCount, vector1.getAccessor().getValueCount());
// Still ok after setting value count?
stringBuilder.setLength(0);
for (int i = 0; i < valueCount; ++i) {
stringBuilder.append('x');
final Object object = accessor1.getObject(i);
assertEquals(stringBuilder.toString(), object.toString());
}
// Combine into a single buffer so we can load it into a new vector.
final DrillBuf[] buffers1 = vector1.getBuffers(false);
@SuppressWarnings("resource") final DrillBuf buffer1 = combineBuffers(allocator, buffers1);
@SuppressWarnings("resource") final NullableVarCharVector vector2 = new NullableVarCharVector(field, allocator);
vector2.load(vector1.getMetadata(), buffer1);
// Check the vector's contents.
final NullableVarCharVector.Accessor accessor2 = vector2.getAccessor();
stringBuilder.setLength(0);
for (int i = 0; i < valueCount; ++i) {
stringBuilder.append('x');
final Object object = accessor2.getObject(i);
assertEquals(stringBuilder.toString(), object.toString());
}
vector1.close();
vector2.close();
buffer1.release();
}
use of io.netty.buffer.DrillBuf in project drill by axbaretto.
the class TestValueVector method testVectorCanLoadEmptyBuffer.
@Test
public void testVectorCanLoadEmptyBuffer() throws Exception {
@SuppressWarnings("resource") final DrillBuf empty = allocator.getEmpty();
testVectors(new VectorVerifier() {
@Override
public void verify(ValueVector vector) {
final String hint = String.format("%s failed the test case", vector.getClass().getSimpleName());
final UserBitShared.SerializedField metadata = vector.getMetadata();
assertEquals(hint, 0, metadata.getBufferLength());
assertEquals(hint, 0, metadata.getValueCount());
vector.load(metadata, empty);
assertEquals(hint, 0, vector.getValueCapacity());
assertEquals(hint, 0, vector.getAccessor().getValueCount());
vector.clear();
}
});
}
use of io.netty.buffer.DrillBuf in project drill by axbaretto.
the class TestVectorLimits method testDirectVariableVector.
/**
* Test a vector directly using the vector mutator to ensure
* that the <tt>setScalar</tt> method works for the maximum
* value count. Uses a DrillBuf as input.
*/
@Test
public void testDirectVariableVector() {
@SuppressWarnings("resource") VarCharVector vector = new VarCharVector(makeField(MinorType.VARCHAR, DataMode.REQUIRED), fixture.allocator());
vector.allocateNew();
// Repeat the big-value test, but with data coming from a DrillBuf
// (direct memory) rather than a heap array.
@SuppressWarnings("resource") DrillBuf drillBuf = makeVarCharValueDirect(260);
VarCharVector.Mutator mutator = vector.getMutator();
int count = 0;
for (; count < 2 * ValueVector.MAX_ROW_COUNT; count++) {
try {
mutator.setScalar(count, drillBuf, 0, 260);
} catch (VectorOverflowException e) {
break;
}
}
drillBuf.close();
// Again, vector should be at the size limit, count below the
// value limit.
mutator.setValueCount(count);
assertEquals(ValueVector.MAX_BUFFER_SIZE, vector.getBuffer().getActualMemoryConsumed());
assertTrue(count < ValueVector.MAX_ROW_COUNT);
vector.close();
}
use of io.netty.buffer.DrillBuf in project drill by axbaretto.
the class TestVectorLimits method makeVarCharValueDirect.
private DrillBuf makeVarCharValueDirect(int n) {
byte[] dummyValue = makeVarCharValue(n);
DrillBuf drillBuf = fixture.allocator().buffer(dummyValue.length);
drillBuf.setBytes(0, dummyValue);
return drillBuf;
}
use of io.netty.buffer.DrillBuf in project drill by axbaretto.
the class TestVectorLimits method testDirectNullableVariableVector.
@Test
public void testDirectNullableVariableVector() {
@SuppressWarnings("resource") NullableVarCharVector vector = new NullableVarCharVector(makeField(MinorType.VARCHAR, DataMode.OPTIONAL), fixture.allocator());
vector.allocateNew();
@SuppressWarnings("resource") DrillBuf drillBuf = makeVarCharValueDirect(260);
NullableVarCharVector.Mutator mutator = vector.getMutator();
int count = 0;
for (; count < 2 * ValueVector.MAX_ROW_COUNT; count++) {
try {
mutator.setScalar(count, drillBuf, 0, 260);
} catch (VectorOverflowException e) {
break;
}
}
drillBuf.close();
mutator.setValueCount(count);
assertEquals(ValueVector.MAX_BUFFER_SIZE, vector.getValuesVector().getBuffer().getActualMemoryConsumed());
assertTrue(count < ValueVector.MAX_ROW_COUNT);
vector.close();
}
Aggregations