Search in sources :

Example 61 with MaterializedField

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

the class ExpressionInterpreterTest method evalExprWithInterpreter.

private ValueVector evalExprWithInterpreter(String expression, RecordBatch batch, Drillbit bit) throws Exception {
    final LogicalExpression expr = parseExpr(expression);
    final ErrorCollector error = new ErrorCollectorImpl();
    final LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, batch, error, bit.getContext().getFunctionImplementationRegistry());
    if (error.getErrorCount() != 0) {
        logger.error("Failure while materializing expression [{}].  Errors: {}", expression, error);
        assertEquals(0, error.getErrorCount());
    }
    final MaterializedField outputField = MaterializedField.create("outCol", materializedExpr.getMajorType());
    final ValueVector vector = TypeHelper.getNewVector(outputField, bit.getContext().getAllocator());
    vector.allocateNewSafe();
    InterpreterEvaluator.evaluate(batch, vector, materializedExpr);
    return vector;
}
Also used : ErrorCollectorImpl(org.apache.drill.common.expression.ErrorCollectorImpl) ValueVector(org.apache.drill.exec.vector.ValueVector) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) ErrorCollector(org.apache.drill.common.expression.ErrorCollector) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Example 62 with MaterializedField

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

the class TestValueVector method testReAllocNullableVariableWidthVector.

@Test
public void testReAllocNullableVariableWidthVector() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVarCharHolder.TYPE);
    // Create a new value vector for 1024 integers
    try (final NullableVarCharVector vector = (NullableVarCharVector) TypeHelper.getNewVector(field, allocator)) {
        final NullableVarCharVector.Mutator m = vector.getMutator();
        vector.allocateNew();
        int initialCapacity = vector.getValueCapacity();
        // Put values in indexes that fall within the initial allocation
        m.setSafe(0, STR1, 0, STR1.length);
        m.setSafe(initialCapacity - 1, STR2, 0, STR2.length);
        // Now try to put values in space that falls beyond the initial allocation
        m.setSafe(initialCapacity + 200, STR3, 0, STR3.length);
        // Check valueCapacity is more than initial allocation
        assertEquals((initialCapacity + 1) * 2 - 1, vector.getValueCapacity());
        final NullableVarCharVector.Accessor accessor = vector.getAccessor();
        assertArrayEquals(STR1, accessor.get(0));
        assertArrayEquals(STR2, accessor.get(initialCapacity - 1));
        assertArrayEquals(STR3, accessor.get(initialCapacity + 200));
        // 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 the current batch is processed.
        m.setValueCount(vector.getValueCapacity() + 200);
    }
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 63 with MaterializedField

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

the class TestValueVector method testVVInitialCapacity.

@Test
public void testVVInitialCapacity() throws Exception {
    final MaterializedField[] fields = new MaterializedField[9];
    final ValueVector[] valueVectors = new ValueVector[9];
    fields[0] = MaterializedField.create(EMPTY_SCHEMA_PATH, BitHolder.TYPE);
    fields[1] = MaterializedField.create(EMPTY_SCHEMA_PATH, IntHolder.TYPE);
    fields[2] = MaterializedField.create(EMPTY_SCHEMA_PATH, VarCharHolder.TYPE);
    fields[3] = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVar16CharHolder.TYPE);
    fields[4] = MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedFloat4Holder.TYPE);
    fields[5] = MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedVarBinaryHolder.TYPE);
    fields[6] = MaterializedField.create(EMPTY_SCHEMA_PATH, MapVector.TYPE);
    fields[6].addChild(fields[0]);
    fields[6].addChild(fields[2]);
    fields[7] = MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedMapVector.TYPE);
    fields[7].addChild(fields[1]);
    fields[7].addChild(fields[3]);
    fields[8] = MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedListVector.TYPE);
    fields[8].addChild(fields[1]);
    final int initialCapacity = 1024;
    try {
        for (int i = 0; i < valueVectors.length; i++) {
            valueVectors[i] = TypeHelper.getNewVector(fields[i], allocator);
            valueVectors[i].setInitialCapacity(initialCapacity);
            valueVectors[i].allocateNew();
        }
        for (int i = 0; i < valueVectors.length; i++) {
            final ValueVector vv = valueVectors[i];
            final int vvCapacity = vv.getValueCapacity();
            // this can't be equality because Nullables will be allocated using power of two sized buffers (thus need 1025
            // spots in one vector > power of two is 2048, available capacity will be 2048 => 2047)
            assertTrue(String.format("Incorrect value capacity for %s [%d]", vv.getField(), vvCapacity), initialCapacity <= vvCapacity);
        }
    } finally {
        AutoCloseables.close(valueVectors);
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) BaseValueVector(org.apache.drill.exec.vector.BaseValueVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 64 with MaterializedField

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

the class TestValueVector method testNullableFloat.

@Test
public void testNullableFloat() {
    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);
        // Put and set a few values.
        m.set(0, 100.1f);
        m.set(1, 101.2f);
        m.set(100, 102.3f);
        m.set(1022, 103.4f);
        m.set(1023, 104.5f);
        final NullableFloat4Vector.Accessor accessor = vector.getAccessor();
        assertEquals(100.1f, accessor.get(0), 0);
        assertEquals(101.2f, accessor.get(1), 0);
        assertEquals(102.3f, accessor.get(100), 0);
        assertEquals(103.4f, accessor.get(1022), 0);
        assertEquals(104.5f, accessor.get(1023), 0);
        // Ensure null values throw.
        {
            boolean b = false;
            try {
                vector.getAccessor().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);
            }
        }
    }
}
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 65 with MaterializedField

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

the class TestValueVector method testListVectorShouldNotThrowOversizedAllocationException.

@Test
public void testListVectorShouldNotThrowOversizedAllocationException() throws Exception {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, Types.optional(TypeProtos.MinorType.LIST));
    ListVector vector = new ListVector(field, allocator, null);
    ListVector vectorFrom = new ListVector(field, allocator, null);
    vectorFrom.allocateNew();
    for (int i = 0; i < 10000; i++) {
        vector.allocateNew();
        vector.copyFromSafe(0, 0, vectorFrom);
        vector.clear();
    }
    vectorFrom.clear();
    vector.clear();
}
Also used : RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) ListVector(org.apache.drill.exec.vector.complex.ListVector) 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