Search in sources :

Example 36 with IntVector

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

the class TestSimpleSort method sortOneKeyAscending.

@Test
public void sortOneKeyAscending() throws Throwable {
    final DrillbitContext bitContext = mockDrillbitContext();
    final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/sort/one_key_sort.json"), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    int previousInt = Integer.MIN_VALUE;
    int recordCount = 0;
    int batchCount = 0;
    while (exec.next()) {
        batchCount++;
        final IntVector c1 = exec.getValueVectorById(new SchemaPath("blue", ExpressionPosition.UNKNOWN), IntVector.class);
        final IntVector c2 = exec.getValueVectorById(new SchemaPath("green", ExpressionPosition.UNKNOWN), IntVector.class);
        final IntVector.Accessor a1 = c1.getAccessor();
        final IntVector.Accessor a2 = c2.getAccessor();
        for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
            recordCount++;
            assertTrue(previousInt <= a1.get(i));
            previousInt = a1.get(i);
            assertEquals(previousInt, a2.get(i));
        }
    }
    System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount));
    if (context.getExecutorState().getFailureCause() != null) {
        throw context.getExecutorState().getFailureCause();
    }
    assertTrue(!context.getExecutorState().isFailed());
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) BigIntVector(org.apache.drill.exec.vector.BigIntVector) IntVector(org.apache.drill.exec.vector.IntVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) UserClientConnection(org.apache.drill.exec.rpc.UserClientConnection) FragmentContextImpl(org.apache.drill.exec.ops.FragmentContextImpl) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 37 with IntVector

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

the class TestSimpleSort method sortTwoKeysOneAscendingOneDescending.

@Test
public void sortTwoKeysOneAscendingOneDescending() throws Throwable {
    final DrillbitContext bitContext = mockDrillbitContext();
    final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/sort/two_key_sort.json"), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    int previousInt = Integer.MIN_VALUE;
    long previousLong = Long.MAX_VALUE;
    int recordCount = 0;
    int batchCount = 0;
    while (exec.next()) {
        batchCount++;
        final IntVector c1 = exec.getValueVectorById(new SchemaPath("blue", ExpressionPosition.UNKNOWN), IntVector.class);
        final BigIntVector c2 = exec.getValueVectorById(new SchemaPath("alt", ExpressionPosition.UNKNOWN), BigIntVector.class);
        final IntVector.Accessor a1 = c1.getAccessor();
        final BigIntVector.Accessor a2 = c2.getAccessor();
        for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
            recordCount++;
            assertTrue(previousInt <= a1.get(i));
            if (previousInt != a1.get(i)) {
                previousLong = Long.MAX_VALUE;
                previousInt = a1.get(i);
            }
            assertTrue(previousLong >= a2.get(i));
        }
    }
    System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount));
    if (context.getExecutorState().getFailureCause() != null) {
        throw context.getExecutorState().getFailureCause();
    }
    assertTrue(!context.getExecutorState().isFailed());
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) BigIntVector(org.apache.drill.exec.vector.BigIntVector) IntVector(org.apache.drill.exec.vector.IntVector) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentContextImpl(org.apache.drill.exec.ops.FragmentContextImpl) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) BigIntVector(org.apache.drill.exec.vector.BigIntVector) SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) SchemaPath(org.apache.drill.common.expression.SchemaPath) UserClientConnection(org.apache.drill.exec.rpc.UserClientConnection) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 38 with IntVector

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

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 39 with IntVector

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

the class TestAgg method oneKeyAgg.

@Test
public void oneKeyAgg() throws Throwable {
    final SimpleRootExec exec = doTest("/agg/test1.json");
    while (exec.next()) {
        final BigIntVector cnt = exec.getValueVectorById(SchemaPath.getSimplePath("cnt"), BigIntVector.class);
        final IntVector key = exec.getValueVectorById(SchemaPath.getSimplePath("blue"), IntVector.class);
        final long[] cntArr = { 10001, 9999 };
        final int[] keyArr = { Integer.MIN_VALUE, Integer.MAX_VALUE };
        for (int i = 0; i < exec.getRecordCount(); i++) {
            assertEquals((Long) cntArr[i], cnt.getAccessor().getObject(i));
            assertEquals((Integer) keyArr[i], key.getAccessor().getObject(i));
        }
    }
    if (exec.getContext().getExecutorState().getFailureCause() != null) {
        throw exec.getContext().getExecutorState().getFailureCause();
    }
    assertTrue(!exec.getContext().getExecutorState().isFailed());
}
Also used : SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) BigIntVector(org.apache.drill.exec.vector.BigIntVector) IntVector(org.apache.drill.exec.vector.IntVector) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) BigIntVector(org.apache.drill.exec.vector.BigIntVector) ExecTest(org.apache.drill.exec.ExecTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 40 with IntVector

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

the class TestAllocators method ensureDrillBufReadIndexIsZero.

/**
 * Contract for DrillBuf[] returned from getBuffers() is that buffers are returned in a reader appropriate state
 * (i.e., readIndex = 0)
 *
 * Before this patch, the following scenario breaks this contract:
 * As data being read from DrillBuf, readIndex will be pushed forward. And, later on,
 * when DrillBuf[] are read from the ValueVector, readIndex will point at the location of the most recent reading
 *
 * This unit test is added to ensure that the readIndex points at zero under this scenario
 */
// DRILL-3854
@Test
public void ensureDrillBufReadIndexIsZero() throws Exception {
    final int length = 10;
    final Properties props = new Properties() {

        {
            put(RootAllocatorFactory.TOP_LEVEL_MAX_ALLOC, "1000000");
        }
    };
    final DrillConfig config = DrillConfig.create(props);
    final BufferAllocator allc = RootAllocatorFactory.newRoot(config);
    final TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder();
    builder.setMinorType(TypeProtos.MinorType.INT);
    builder.setMode(TypeProtos.DataMode.REQUIRED);
    final IntVector iv = new IntVector(MaterializedField.create("Field", builder.build()), allc);
    iv.allocateNew();
    // Write data to DrillBuf
    for (int i = 0; i < length; ++i) {
        iv.getBuffer().writeInt(i);
    }
    // Read data to DrillBuf
    for (int i = 0; i < length; ++i) {
        assertEquals(i, iv.getBuffer().readInt());
    }
    for (DrillBuf drillBuf : iv.getBuffers(false)) {
        assertEquals(0, drillBuf.readInt());
    }
    final List<DrillBuf> toBeClean = Lists.newArrayList();
    for (DrillBuf drillBuf : iv.getBuffers(true)) {
        assertEquals(0, drillBuf.readInt());
        toBeClean.add(drillBuf);
    }
    for (DrillBuf drillBuf : toBeClean) {
        drillBuf.release();
    }
    allc.close();
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) IntVector(org.apache.drill.exec.vector.IntVector) Properties(java.util.Properties) DrillBuf(io.netty.buffer.DrillBuf) MemoryTest(org.apache.drill.categories.MemoryTest) DrillTest(org.apache.drill.test.DrillTest) 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