Search in sources :

Example 11 with MaterializedField

use of org.apache.drill.exec.record.MaterializedField in project drill by apache.

the class TestValueVector method testVectors.

/**
   * Convenience method that allows running tests on various {@link ValueVector vector} instances.
   *
   * @param test test function to execute
   */
private void testVectors(VectorVerifier test) throws Exception {
    final MaterializedField[] fields = { MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, BitHolder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, VarCharHolder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVarCharHolder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedListVector.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, MapVector.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedMapVector.TYPE) };
    final ValueVector[] vectors = { new UInt4Vector(fields[0], allocator), new BitVector(fields[1], allocator), new VarCharVector(fields[2], allocator), new NullableVarCharVector(fields[3], allocator), new RepeatedListVector(fields[4], allocator, null), new MapVector(fields[5], allocator, null), new RepeatedMapVector(fields[6], allocator, null) };
    try {
        for (final ValueVector vector : vectors) {
            test.verify(vector);
        }
    } finally {
        AutoCloseables.close(vectors);
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) BaseValueVector(org.apache.drill.exec.vector.BaseValueVector) BitVector(org.apache.drill.exec.vector.BitVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) NullableUInt4Vector(org.apache.drill.exec.vector.NullableUInt4Vector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) MapVector(org.apache.drill.exec.vector.complex.MapVector)

Example 12 with MaterializedField

use of org.apache.drill.exec.record.MaterializedField in project drill by apache.

the class TestValueVector method testNullableFixedType.

@Test
public void testNullableFixedType() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableUInt4Holder.TYPE);
    // Create a new value vector for 1024 integers.
    try (final NullableUInt4Vector vector = new NullableUInt4Vector(field, allocator)) {
        final NullableUInt4Vector.Mutator m = vector.getMutator();
        vector.allocateNew(1024);
        // Put and set a few values
        m.set(0, 100);
        m.set(1, 101);
        m.set(100, 102);
        m.set(1022, 103);
        m.set(1023, 104);
        final NullableUInt4Vector.Accessor accessor = vector.getAccessor();
        assertEquals(100, accessor.get(0));
        assertEquals(101, accessor.get(1));
        assertEquals(102, accessor.get(100));
        assertEquals(103, accessor.get(1022));
        assertEquals(104, accessor.get(1023));
        // Ensure null values throw
        {
            boolean b = false;
            try {
                accessor.get(3);
            } catch (IllegalStateException e) {
                b = true;
            } finally {
                assertTrue(b);
            }
        }
        vector.allocateNew(2048);
        {
            boolean b = false;
            try {
                accessor.get(0);
            } catch (IllegalStateException e) {
                b = true;
            } finally {
                assertTrue(b);
            }
        }
        m.set(0, 100);
        m.set(1, 101);
        m.set(100, 102);
        m.set(1022, 103);
        m.set(1023, 104);
        assertEquals(100, accessor.get(0));
        assertEquals(101, accessor.get(1));
        assertEquals(102, accessor.get(100));
        assertEquals(103, accessor.get(1022));
        assertEquals(104, accessor.get(1023));
        // Ensure null values throw.
        {
            boolean b = false;
            try {
                vector.getAccessor().get(3);
            } catch (IllegalStateException e) {
                b = true;
            } finally {
                assertTrue(b);
            }
        }
    }
}
Also used : NullableUInt4Vector(org.apache.drill.exec.vector.NullableUInt4Vector) MaterializedField(org.apache.drill.exec.record.MaterializedField) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 13 with MaterializedField

use of org.apache.drill.exec.record.MaterializedField in project drill by apache.

the class TestValueVector method testVarCharVectorLoad.

@Test
public void testVarCharVectorLoad() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, VarCharHolder.TYPE);
    // Create a new value vector for 1024 variable length strings.
    final VarCharVector vector1 = new VarCharVector(field, allocator);
    final VarCharVector.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.setSafe(i, stringBuilder.toString().getBytes(utf8Charset));
    }
    mutator.setValueCount(valueCount);
    assertEquals(valueCount, vector1.getAccessor().getValueCount());
    // Combine the backing buffers so we can load them into a new vector.
    final DrillBuf[] buffers1 = vector1.getBuffers(false);
    final DrillBuf buffer1 = combineBuffers(allocator, buffers1);
    final VarCharVector vector2 = new VarCharVector(field, allocator);
    vector2.load(vector1.getMetadata(), buffer1);
    // Check the contents of the new vector.
    final VarCharVector.Accessor accessor = vector2.getAccessor();
    stringBuilder.setLength(0);
    for (int i = 0; i < valueCount; ++i) {
        stringBuilder.append('x');
        final Object object = accessor.getObject(i);
        assertEquals(stringBuilder.toString(), object.toString());
    }
    vector1.close();
    vector2.close();
    buffer1.release();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) DrillBuf(io.netty.buffer.DrillBuf) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 14 with MaterializedField

use of org.apache.drill.exec.record.MaterializedField in project drill by apache.

the class TestValueVector method testFixedVectorReallocation.

@Test(expected = OversizedAllocationException.class)
public void testFixedVectorReallocation() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE);
    final UInt4Vector vector = new UInt4Vector(field, allocator);
    // edge case 1: buffer size = max value capacity
    final int expectedValueCapacity = BaseValueVector.MAX_ALLOCATION_SIZE / 4;
    try {
        vector.allocateNew(expectedValueCapacity);
        assertEquals(expectedValueCapacity, vector.getValueCapacity());
        vector.reAlloc();
        assertEquals(expectedValueCapacity * 2, vector.getValueCapacity());
    } finally {
        vector.close();
    }
    // common case: value count < max value capacity
    try {
        vector.allocateNew(BaseValueVector.MAX_ALLOCATION_SIZE / 8);
        // value allocation reaches to MAX_VALUE_ALLOCATION
        vector.reAlloc();
        // this should throw an IOOB
        vector.reAlloc();
    } finally {
        vector.close();
    }
}
Also used : MaterializedField(org.apache.drill.exec.record.MaterializedField) NullableUInt4Vector(org.apache.drill.exec.vector.NullableUInt4Vector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 15 with MaterializedField

use of org.apache.drill.exec.record.MaterializedField in project drill by apache.

the class TestValueVector method testBitVectorReallocation.

@Test(expected = OversizedAllocationException.class)
public void testBitVectorReallocation() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE);
    final BitVector vector = new BitVector(field, allocator);
    // edge case 1: buffer size ~ max value capacity
    final int expectedValueCapacity = 1 << 29;
    try {
        vector.allocateNew(expectedValueCapacity);
        assertEquals(expectedValueCapacity, vector.getValueCapacity());
        vector.reAlloc();
        assertEquals(expectedValueCapacity * 2, vector.getValueCapacity());
    } finally {
        vector.close();
    }
    // common: value count < MAX_VALUE_ALLOCATION
    try {
        vector.allocateNew(expectedValueCapacity);
        for (int i = 0; i < 3; i++) {
            // expand buffer size
            vector.reAlloc();
        }
        assertEquals(Integer.MAX_VALUE, vector.getValueCapacity());
        // buffer size ~ max allocation
        vector.reAlloc();
        assertEquals(Integer.MAX_VALUE, vector.getValueCapacity());
        // overflow
        vector.reAlloc();
    } finally {
        vector.close();
    }
}
Also used : BitVector(org.apache.drill.exec.vector.BitVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Aggregations

MaterializedField (org.apache.drill.exec.record.MaterializedField)67 ValueVector (org.apache.drill.exec.vector.ValueVector)29 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)20 Test (org.junit.Test)18 ExecTest (org.apache.drill.exec.ExecTest)16 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)13 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)11 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)9 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)9 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)9 VectorContainer (org.apache.drill.exec.record.VectorContainer)8 IOException (java.io.IOException)7 BatchSchema (org.apache.drill.exec.record.BatchSchema)7 SchemaPath (org.apache.drill.common.expression.SchemaPath)6 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)6 ValueVectorWriteExpression (org.apache.drill.exec.expr.ValueVectorWriteExpression)6 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)5 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)5 DrillBuf (io.netty.buffer.DrillBuf)4 ArrayList (java.util.ArrayList)4