Search in sources :

Example 86 with DrillBuf

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();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) DrillBuf(io.netty.buffer.DrillBuf) VectorTest(org.apache.drill.categories.VectorTest) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 87 with DrillBuf

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();
        }
    });
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) BaseValueVector(org.apache.drill.exec.vector.BaseValueVector) DrillBuf(io.netty.buffer.DrillBuf) VectorTest(org.apache.drill.categories.VectorTest) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 88 with DrillBuf

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();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) VectorOverflowException(org.apache.drill.exec.vector.VectorOverflowException) DrillBuf(io.netty.buffer.DrillBuf) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest) DrillTest(org.apache.drill.test.DrillTest)

Example 89 with DrillBuf

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;
}
Also used : DrillBuf(io.netty.buffer.DrillBuf)

Example 90 with 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();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VectorOverflowException(org.apache.drill.exec.vector.VectorOverflowException) DrillBuf(io.netty.buffer.DrillBuf) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest) DrillTest(org.apache.drill.test.DrillTest)

Aggregations

DrillBuf (io.netty.buffer.DrillBuf)187 Test (org.junit.Test)63 MemoryTest (org.apache.drill.categories.MemoryTest)38 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)22 ValueVector (org.apache.drill.exec.vector.ValueVector)18 BaseTest (org.apache.drill.test.BaseTest)18 MaterializedField (org.apache.drill.exec.record.MaterializedField)16 IOException (java.io.IOException)13 VectorTest (org.apache.drill.categories.VectorTest)13 OutOfMemoryException (org.apache.drill.exec.exception.OutOfMemoryException)13 ExecTest (org.apache.drill.exec.ExecTest)11 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)11 VectorContainer (org.apache.drill.exec.record.VectorContainer)10 Stopwatch (com.google.common.base.Stopwatch)9 ByteBuffer (java.nio.ByteBuffer)9 BatchSchema (org.apache.drill.exec.record.BatchSchema)9 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)8 UserBitShared (org.apache.drill.exec.proto.UserBitShared)8 SerializedField (org.apache.drill.exec.proto.UserBitShared.SerializedField)8 DrillTest (org.apache.drill.test.DrillTest)8