Search in sources :

Example 21 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan 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)

Example 22 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class PlanSplitter method getFragments.

private List<PlanFragment> getFragments(final DrillbitContext dContext, final GetQueryPlanFragments req, final QueryContext queryContext, final QueryId queryId) throws Exception {
    final PhysicalPlan plan;
    final String query = req.getQuery();
    switch(req.getType()) {
        case SQL:
            final Pointer<String> textPlan = new Pointer<>();
            plan = DrillSqlWorker.getPlan(queryContext, query, textPlan);
            break;
        case PHYSICAL:
            plan = dContext.getPlanReader().readPhysicalPlan(query);
            break;
        default:
            throw new IllegalStateException("Planning fragments supports only SQL or PHYSICAL QueryType");
    }
    MemoryAllocationUtilities.setupSortMemoryAllocations(plan, queryContext);
    final PhysicalOperator rootOperator = plan.getSortedOperators(false).iterator().next();
    final Fragment rootFragment = rootOperator.accept(MakeFragmentsVisitor.INSTANCE, null);
    final SimpleParallelizer parallelizer = new SplittingParallelizer(queryContext);
    List<PlanFragment> fragments = Lists.newArrayList();
    if (req.getSplitPlan()) {
        final List<QueryWorkUnit> queryWorkUnits = parallelizer.getSplitFragments(queryContext.getOptions().getOptionList(), queryContext.getCurrentEndpoint(), queryId, queryContext.getActiveEndpoints(), dContext.getPlanReader(), rootFragment, queryContext.getSession(), queryContext.getQueryContextInfo());
        for (QueryWorkUnit queryWorkUnit : queryWorkUnits) {
            fragments.add(queryWorkUnit.getRootFragment());
            List<PlanFragment> childFragments = queryWorkUnit.getFragments();
            if (!childFragments.isEmpty()) {
                throw new IllegalStateException("Split plans can not have more then one fragment");
            }
        }
    } else {
        final QueryWorkUnit queryWorkUnit = parallelizer.getFragments(queryContext.getOptions().getOptionList(), queryContext.getCurrentEndpoint(), queryId, queryContext.getActiveEndpoints(), dContext.getPlanReader(), rootFragment, queryContext.getSession(), queryContext.getQueryContextInfo());
        fragments.add(queryWorkUnit.getRootFragment());
        fragments.addAll(queryWorkUnit.getFragments());
    }
    return fragments;
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) QueryWorkUnit(org.apache.drill.exec.work.QueryWorkUnit) SimpleParallelizer(org.apache.drill.exec.planner.fragment.SimpleParallelizer) Pointer(org.apache.drill.exec.util.Pointer) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) Fragment(org.apache.drill.exec.planner.fragment.Fragment) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) SplittingParallelizer(org.apache.drill.exec.planner.fragment.contrib.SplittingParallelizer)

Example 23 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class TestTraceOutputDump method testFilter.

@Test
public void testFilter(@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("/trace/simple_trace.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()));
    while (exec.next()) {
    }
    exec.close();
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
    final FragmentHandle handle = context.getHandle();
    /* Form the file name to which the trace output will dump the record batches */
    final String qid = QueryIdHelper.getQueryId(handle.getQueryId());
    final int majorFragmentId = handle.getMajorFragmentId();
    final int minorFragmentId = handle.getMinorFragmentId();
    final String logLocation = c.getString(ExecConstants.TRACE_DUMP_DIRECTORY);
    System.out.println("Found log location: " + logLocation);
    final String filename = String.format("%s//%s_%d_%d_mock-scan", logLocation, qid, majorFragmentId, minorFragmentId);
    System.out.println("File Name: " + filename);
    final Configuration conf = new Configuration();
    conf.set(FileSystem.FS_DEFAULT_NAME_KEY, c.getString(ExecConstants.TRACE_DUMP_FILESYSTEM));
    final FileSystem fs = FileSystem.get(conf);
    final Path path = new Path(filename);
    assertTrue("Trace file does not exist", fs.exists(path));
    final FSDataInputStream in = fs.open(path);
    final VectorAccessibleSerializable wrap = new VectorAccessibleSerializable(context.getAllocator());
    wrap.readFromStream(in);
    final VectorAccessible container = wrap.get();
    /* Assert there are no selection vectors */
    assertTrue(wrap.getSv2() == null);
    /* Assert there is only one record */
    assertTrue(container.getRecordCount() == 1);
    /* Read the Integer value and ASSERT its Integer.MIN_VALUE */
    final int value = (int) container.iterator().next().getValueVector().getAccessor().getObject(0);
    assertTrue(value == Integer.MIN_VALUE);
}
Also used : Path(org.apache.hadoop.fs.Path) VectorAccessibleSerializable(org.apache.drill.exec.cache.VectorAccessibleSerializable) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) Configuration(org.apache.hadoop.conf.Configuration) VectorAccessible(org.apache.drill.exec.record.VectorAccessible) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FragmentHandle(org.apache.drill.exec.proto.ExecProtos.FragmentHandle) SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 24 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class TestSimpleUnion method testUnion.

@Test
public void testUnion(@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("/union/test1.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()));
    final int[] counts = new int[] { 100, 50 };
    int i = 0;
    while (exec.next()) {
        System.out.println("iteration count:" + exec.getRecordCount());
        assertEquals(counts[i++], exec.getRecordCount());
    }
    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) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest)

Example 25 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class PhysicalPlanCreator method build.

public PhysicalPlan build(Prel rootPrel, boolean forceRebuild) {
    if (plan != null && !forceRebuild) {
        return plan;
    }
    PlanPropertiesBuilder propsBuilder = PlanProperties.builder();
    propsBuilder.type(PlanType.APACHE_DRILL_PHYSICAL);
    propsBuilder.version(1);
    propsBuilder.resultMode(ResultMode.EXEC);
    propsBuilder.generator(PhysicalPlanCreator.class.getName(), "");
    try {
        // invoke getPhysicalOperator on the root Prel which will recursively invoke it
        // on the descendants and we should have a well-formed physical operator tree
        PhysicalOperator rootPOP = rootPrel.getPhysicalOperator(this);
        if (rootPOP != null) {
            //getPhysicalOperator() is supposed to populate this list
            assert (popList.size() > 0);
            plan = new PhysicalPlan(propsBuilder.build(), popList);
        }
    } catch (IOException e) {
        plan = null;
        throw new UnsupportedOperationException("Physical plan created failed with error : " + e.toString());
    }
    return plan;
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) PlanPropertiesBuilder(org.apache.drill.common.logical.PlanProperties.PlanPropertiesBuilder) IOException(java.io.IOException)

Aggregations

PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)58 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)43 FragmentContext (org.apache.drill.exec.ops.FragmentContext)41 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)41 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)39 Test (org.junit.Test)34 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)24 ExecTest (org.apache.drill.exec.ExecTest)16 SchemaPath (org.apache.drill.common.expression.SchemaPath)15 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)13 ValueVector (org.apache.drill.exec.vector.ValueVector)8 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)6 BigIntVector (org.apache.drill.exec.vector.BigIntVector)6 IntVector (org.apache.drill.exec.vector.IntVector)6 Ignore (org.junit.Ignore)5 DrillConfig (org.apache.drill.common.config.DrillConfig)4 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)4 IOException (java.io.IOException)3 RelNode (org.apache.calcite.rel.RelNode)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3