Search in sources :

Example 66 with MaterializedField

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

the class TestValueVector method testReAllocNullableFixedWidthVector.

@Test
public void testReAllocNullableFixedWidthVector() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableFloat4Holder.TYPE);
    // Create a new value vector for 1024 integers
    try (final NullableFloat4Vector vector = (NullableFloat4Vector) TypeHelper.getNewVector(field, allocator)) {
        final NullableFloat4Vector.Mutator m = vector.getMutator();
        vector.allocateNew(1024);
        assertEquals(1024, vector.getValueCapacity());
        // Put values in indexes that fall within the initial allocation
        m.setSafe(0, 100.1f);
        m.setSafe(100, 102.3f);
        m.setSafe(1023, 104.5f);
        // Now try to put values in space that falls beyond the initial allocation
        m.setSafe(2000, 105.5f);
        // Check valueCapacity is more than initial allocation
        assertEquals(1024 * 2, vector.getValueCapacity());
        final NullableFloat4Vector.Accessor accessor = vector.getAccessor();
        assertEquals(100.1f, accessor.get(0), 0);
        assertEquals(102.3f, accessor.get(100), 0);
        assertEquals(104.5f, accessor.get(1023), 0);
        assertEquals(105.5f, accessor.get(2000), 0);
        // Set the valueCount to be more than valueCapacity of current allocation. This is possible for NullableValueVectors
        // as we don't call setSafe for null values, but we do call setValueCount when all values are inserted into the
        // vector
        m.setValueCount(vector.getValueCapacity() + 200);
    }
}
Also used : NullableFloat4Vector(org.apache.drill.exec.vector.NullableFloat4Vector) MaterializedField(org.apache.drill.exec.record.MaterializedField) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 67 with MaterializedField

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

the class BaseRepeatedValueVector method addOrGetVector.

@Override
public <T extends ValueVector> AddOrGetResult<T> addOrGetVector(VectorDescriptor descriptor) {
    boolean created = false;
    if (vector == DEFAULT_DATA_VECTOR && descriptor.getType().getMinorType() != TypeProtos.MinorType.LATE) {
        final MaterializedField field = descriptor.withName(DATA_VECTOR_NAME).getField();
        vector = BasicTypeHelper.getNewVector(field, allocator);
        // returned vector must have the same field
        assert field.equals(vector.getField());
        getField().addChild(field);
        created = true;
    }
    final TypeProtos.MajorType actual = vector.getField().getType();
    if (!actual.equals(descriptor.getType())) {
        final String msg = String.format("Inner vector type mismatch. Requested type: [%s], actual type: [%s]", descriptor.getType(), actual);
        throw new SchemaChangeRuntimeException(msg);
    }
    return new AddOrGetResult<>((T) vector, created);
}
Also used : MaterializedField(org.apache.drill.exec.record.MaterializedField) SchemaChangeRuntimeException(org.apache.drill.exec.exception.SchemaChangeRuntimeException) TypeProtos(org.apache.drill.common.types.TypeProtos) AddOrGetResult(org.apache.drill.exec.vector.AddOrGetResult)

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