Search in sources :

Example 26 with IntVector

use of org.apache.drill.exec.vector.IntVector in project drill by apache.

the class TestFixedWidthWriter method allocVector.

private IntVector allocVector(int size) {
    MaterializedField field = SchemaBuilder.columnSchema("x", MinorType.INT, DataMode.REQUIRED);
    IntVector vector = new IntVector(field, fixture.allocator());
    vector.allocateNew(size);
    for (int i = 0; i < size; i++) {
        vector.getMutator().set(i, 0xdeadbeef);
    }
    return vector;
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Example 27 with IntVector

use of org.apache.drill.exec.vector.IntVector in project drill by apache.

the class TestFixedWidthWriter method testFillEmpties.

/**
 * Required, fixed-width vectors are back-filling with 0 to fill in missing
 * values. While using zero is not strictly SQL compliant, it is better
 * than failing. (The SQL solution would be to fill with nulls, but a
 * required vector does not support nulls...)
 */
@Test
public void testFillEmpties() {
    try (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        for (int i = 0; i < 501; i += 5) {
            index.index = i;
            writer.startRow();
            writer.setInt(i);
            writer.saveRow();
        }
        // At end, vector index defined to point one past the
        // last row. That is, the vector index gives the row count.
        index.index = 504;
        writer.endWrite();
        for (int i = 0; i < 504; i++) {
            assertEquals("Mismatch on " + i, (i % 5) == 0 ? i : 0, vector.getAccessor().get(i));
        }
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 28 with IntVector

use of org.apache.drill.exec.vector.IntVector in project drill by apache.

the class TestShortArrays method testReAllocZeroSize.

/**
 * Test that a zero-length vector, on reAlloc, will default
 * to 256 bytes. (Previously the code just doubled zero
 * forever.)
 */
@Test
public void testReAllocZeroSize() {
    try (IntVector vector = new IntVector(SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED), fixture.allocator())) {
        vector.allocateNew(0);
        vector.reAlloc();
        assertEquals(256 / 4, vector.getValueCapacity());
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) RepeatedIntVector(org.apache.drill.exec.vector.RepeatedIntVector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 29 with IntVector

use of org.apache.drill.exec.vector.IntVector in project drill by apache.

the class TestMathFunctions method testBasicMathFunctions.

@Test
public void testBasicMathFunctions(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/simple_math_functions.json"), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    while (exec.next()) {
        final IntVector intMulVector = exec.getValueVectorById(new SchemaPath("INTMUL", ExpressionPosition.UNKNOWN), IntVector.class);
        final Float8Vector floatMulVector = exec.getValueVectorById(new SchemaPath("FLOATMUL", ExpressionPosition.UNKNOWN), Float8Vector.class);
        final IntVector intAddVector = exec.getValueVectorById(new SchemaPath("INTADD", ExpressionPosition.UNKNOWN), IntVector.class);
        final Float8Vector floatAddVector = exec.getValueVectorById(new SchemaPath("FLOATADD", ExpressionPosition.UNKNOWN), Float8Vector.class);
        assertEquals(exec.getRecordCount(), 1);
        assertEquals(intMulVector.getAccessor().get(0), 2);
        assertEquals(floatMulVector.getAccessor().get(0), (1.1 * 2.2), 0);
        assertEquals(intAddVector.getAccessor().get(0), 3);
        assertEquals(floatAddVector.getAccessor().get(0), (1.1 + 2.2), 0);
    }
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) IntVector(org.apache.drill.exec.vector.IntVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) Float8Vector(org.apache.drill.exec.vector.Float8Vector) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest)

Example 30 with IntVector

use of org.apache.drill.exec.vector.IntVector in project drill by apache.

the class ExpressionTest method testSpecial.

@Test
public void testSpecial(@Injectable final RecordBatch batch, @Injectable ValueVector vector) throws Exception {
    final TypeProtos.MajorType type = Types.optional(MinorType.INT);
    final TypedFieldId tfid = new TypedFieldId(type, false, 0);
    new NonStrictExpectations() {

        @NonStrict
        VectorWrapper<?> wrapper;

        {
            batch.getValueVectorId(new SchemaPath("alpha", ExpressionPosition.UNKNOWN));
            result = tfid;
            batch.getValueAccessorById(IntVector.class, tfid.getFieldIds());
            result = wrapper;
            wrapper.getValueVector();
            result = new IntVector(MaterializedField.create("result", type), RootAllocatorFactory.newRoot(c));
        }
    };
    System.out.println(getExpressionCode("1 + 1", batch));
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) TypedFieldId(org.apache.drill.exec.record.TypedFieldId) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) TypeProtos(org.apache.drill.common.types.TypeProtos) NonStrictExpectations(mockit.NonStrictExpectations) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Aggregations

IntVector (org.apache.drill.exec.vector.IntVector)69 Test (org.junit.Test)56 BigIntVector (org.apache.drill.exec.vector.BigIntVector)26 SchemaPath (org.apache.drill.common.expression.SchemaPath)23 ExecTest (org.apache.drill.exec.ExecTest)22 SubOperatorTest (org.apache.drill.test.SubOperatorTest)21 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)18 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)18 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)18 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)18 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)18 OperatorTest (org.apache.drill.categories.OperatorTest)14 IntColumnWriter (org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter)14 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)13 FragmentContextImpl (org.apache.drill.exec.ops.FragmentContextImpl)12 UserClientConnection (org.apache.drill.exec.rpc.UserClientConnection)12 BigIntHolder (org.apache.drill.exec.expr.holders.BigIntHolder)6 IntHolder (org.apache.drill.exec.expr.holders.IntHolder)6 FragmentContext (org.apache.drill.exec.ops.FragmentContext)6 MaterializedField (org.apache.drill.exec.record.MaterializedField)6