Search in sources :

Example 6 with SimpleRootExec

use of org.apache.drill.exec.physical.impl.SimpleRootExec in project drill by apache.

the class TestSimpleLimit method verifyLimitCount.

private void verifyLimitCount(DrillbitContext bitContext, UserClientConnection connection, String testPlan, int expectedCount) throws Throwable {
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/limit/" + testPlan), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    int recordCount = 0;
    while (exec.next()) {
        recordCount += exec.getRecordCount();
    }
    assertEquals(expectedCount, recordCount);
    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) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)

Example 7 with SimpleRootExec

use of org.apache.drill.exec.physical.impl.SimpleRootExec in project drill by apache.

the class TestSimpleLimit method verifySum.

private void verifySum(DrillbitContext bitContext, UserClientConnection connection, String testPlan, int expectedCount, long expectedSum) throws Throwable {
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/limit/" + testPlan), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    int recordCount = 0;
    long sum = 0;
    while (exec.next()) {
        recordCount += exec.getRecordCount();
        final BigIntVector v = (BigIntVector) exec.iterator().next();
        for (int i = 0; i < v.getAccessor().getValueCount(); i++) {
            sum += v.getAccessor().get(i);
        }
    }
    assertEquals(expectedCount, recordCount);
    assertEquals(expectedSum, sum);
    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) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) BigIntVector(org.apache.drill.exec.vector.BigIntVector)

Example 8 with SimpleRootExec

use of org.apache.drill.exec.physical.impl.SimpleRootExec in project drill by apache.

the class TestAgg method twoKeyAgg.

@Test
public void twoKeyAgg(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    SimpleRootExec exec = doTest(bitContext, connection, "/agg/twokey.json");
    while (exec.next()) {
        final IntVector key1 = exec.getValueVectorById(SchemaPath.getSimplePath("key1"), IntVector.class);
        final BigIntVector key2 = exec.getValueVectorById(SchemaPath.getSimplePath("key2"), BigIntVector.class);
        final BigIntVector cnt = exec.getValueVectorById(SchemaPath.getSimplePath("cnt"), BigIntVector.class);
        final NullableBigIntVector total = exec.getValueVectorById(SchemaPath.getSimplePath("total"), NullableBigIntVector.class);
        final Integer[] keyArr1 = { Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE };
        final long[] keyArr2 = { 0, 1, 2, 0, 1, 2 };
        final long[] cntArr = { 34, 34, 34, 34, 34, 34 };
        final long[] totalArr = { 0, 34, 68, 0, 34, 68 };
        for (int i = 0; i < exec.getRecordCount(); i++) {
            //        System.out.print(key1.getAccessor().getObject(i));
            //        System.out.print("\t");
            //        System.out.print(key2.getAccessor().getObject(i));
            //        System.out.print("\t");
            //        System.out.print(cnt.getAccessor().getObject(i));
            //        System.out.print("\t");
            //        System.out.print(total.getAccessor().getObject(i));
            //        System.out.println();
            assertEquals((Long) cntArr[i], cnt.getAccessor().getObject(i));
            assertEquals(keyArr1[i], key1.getAccessor().getObject(i));
            assertEquals((Long) keyArr2[i], key2.getAccessor().getObject(i));
            assertEquals((Long) totalArr[i], total.getAccessor().getObject(i));
        }
    }
    if (exec.getContext().getFailureCause() != null) {
        throw exec.getContext().getFailureCause();
    }
    assertTrue(!exec.getContext().isFailed());
}
Also used : SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) BigIntVector(org.apache.drill.exec.vector.BigIntVector) IntVector(org.apache.drill.exec.vector.IntVector) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) BigIntVector(org.apache.drill.exec.vector.BigIntVector) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest)

Example 9 with SimpleRootExec

use of org.apache.drill.exec.physical.impl.SimpleRootExec in project drill by apache.

the class TestNewMathFunctions method runTest.

public void runTest(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable {
    mockDrillbitContext(bitContext);
    final String planString = Resources.toString(Resources.getResource(planPath), Charsets.UTF_8);
    if (reader == null) {
        reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    }
    if (registry == null) {
        registry = new FunctionImplementationRegistry(c);
    }
    if (context == null) {
        //new FragmentContext(bitContext, ExecProtos.FragmentHandle.getDefaultInstance(), connection, registry);
        context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    }
    final PhysicalPlan plan = reader.readPhysicalPlan(planString);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    // skip schema batch
    exec.next();
    while (exec.next()) {
        final Object[] res = getRunResult(exec);
        assertEquals("return count does not match", expectedResults.length, res.length);
        for (int i = 0; i < res.length; i++) {
            assertEquals(String.format("column %s does not match", i), res[i], expectedResults[i]);
        }
    }
    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) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)

Example 10 with SimpleRootExec

use of org.apache.drill.exec.physical.impl.SimpleRootExec in project drill by apache.

the class TestRepeatedFunction method testRepeated.

@Test
public void testRepeated(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    //    System.out.println(System.getProperty("java.class.path"));
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/physical_repeated_1.json"), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    boolean oneIsOne = false;
    int size = 0;
    final int[] sizes = { 1, 2, 0, 6 };
    while (exec.next()) {
        final IntVector c1 = exec.getValueVectorById(new SchemaPath("cnt", ExpressionPosition.UNKNOWN), IntVector.class);
        final BitVector c2 = exec.getValueVectorById(new SchemaPath("has_min", ExpressionPosition.UNKNOWN), BitVector.class);
        for (int i = 0; i < exec.getRecordCount(); i++) {
            final int curSize = sizes[size % sizes.length];
            assertEquals(curSize, c1.getAccessor().get(i));
            switch(curSize) {
                case 1:
                    assertEquals(oneIsOne, 1 == c2.getAccessor().get(i));
                    oneIsOne = !oneIsOne;
                    break;
                case 2:
                    assertEquals(1, c2.getAccessor().get(i));
                    break;
                case 0:
                    assertEquals(0, c2.getAccessor().get(i));
                    break;
                case 6:
                    assertEquals(1, c2.getAccessor().get(i));
                    break;
            }
            size++;
        }
    }
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) BitVector(org.apache.drill.exec.vector.BitVector) 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) 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)

Aggregations

SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)26 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)24 FragmentContext (org.apache.drill.exec.ops.FragmentContext)24 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)24 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)23 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)23 Test (org.junit.Test)20 ExecTest (org.apache.drill.exec.ExecTest)13 ValueVector (org.apache.drill.exec.vector.ValueVector)8 IntVector (org.apache.drill.exec.vector.IntVector)6 SchemaPath (org.apache.drill.common.expression.SchemaPath)5 BigIntVector (org.apache.drill.exec.vector.BigIntVector)5 Ignore (org.junit.Ignore)5 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)3 NullableBigIntVector (org.apache.drill.exec.vector.NullableBigIntVector)3 OpProfileDef (org.apache.drill.exec.ops.OpProfileDef)2 OperatorStats (org.apache.drill.exec.ops.OperatorStats)2 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)2 FragmentHandle (org.apache.drill.exec.proto.ExecProtos.FragmentHandle)2 Configuration (org.apache.hadoop.conf.Configuration)2