Search in sources :

Example 26 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

the class TestLocalExchange method testHelperVerifyPartitionSenderParallelization.

// Verify the number of partition senders in a major fragments is not more than the cluster size and each endpoint
// in the cluster has at most one fragment from a given major fragment that has the partition sender.
private static void testHelperVerifyPartitionSenderParallelization(String plan, boolean isMuxOn, boolean isDeMuxOn) throws Exception {
    final DrillbitContext drillbitContext = getDrillbitContext();
    final PhysicalPlanReader planReader = drillbitContext.getPlanReader();
    final Fragment rootFragment = PopUnitTestBase.getRootFragmentFromPlanString(planReader, plan);
    final List<Integer> deMuxFragments = Lists.newLinkedList();
    final List<Integer> htrFragments = Lists.newLinkedList();
    final PlanningSet planningSet = new PlanningSet();
    // Create a planningSet to get the assignment of major fragment ids to fragments.
    PARALLELIZER.initFragmentWrappers(rootFragment, planningSet);
    findFragmentsWithPartitionSender(rootFragment, planningSet, deMuxFragments, htrFragments);
    final QueryContextInformation queryContextInfo = Utilities.createQueryContextInfo("dummySchemaName", "938ea2d9-7cb9-4baf-9414-a5a0b7777e8e");
    QueryWorkUnit qwu = PARALLELIZER.getFragments(new OptionList(), drillbitContext.getEndpoint(), QueryId.getDefaultInstance(), drillbitContext.getBits(), rootFragment, USER_SESSION, queryContextInfo);
    qwu.applyPlan(planReader);
    // Make sure the number of minor fragments with HashPartitioner within a major fragment is not more than the
    // number of Drillbits in cluster
    ArrayListMultimap<Integer, DrillbitEndpoint> partitionSenderMap = ArrayListMultimap.create();
    for (PlanFragment planFragment : qwu.getFragments()) {
        if (planFragment.getFragmentJson().contains("hash-partition-sender")) {
            int majorFragmentId = planFragment.getHandle().getMajorFragmentId();
            DrillbitEndpoint assignedEndpoint = planFragment.getAssignment();
            partitionSenderMap.get(majorFragmentId).add(assignedEndpoint);
        }
    }
    if (isMuxOn) {
        verifyAssignment(htrFragments, partitionSenderMap);
    }
    if (isDeMuxOn) {
        verifyAssignment(deMuxFragments, partitionSenderMap);
    }
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) QueryWorkUnit(org.apache.drill.exec.work.QueryWorkUnit) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) Fragment(org.apache.drill.exec.planner.fragment.Fragment) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) PlanningSet(org.apache.drill.exec.planner.fragment.PlanningSet) QueryContextInformation(org.apache.drill.exec.proto.BitControl.QueryContextInformation) OptionList(org.apache.drill.exec.server.options.OptionList)

Example 27 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

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");
    }
    QueryResourceAllocator planner = dContext.getResourceManager().newResourceAllocator(queryContext);
    planner.visitAbstractPlan(plan);
    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) {
            planner.visitPhysicalPlan(queryWorkUnit);
            queryWorkUnit.applyPlan(dContext.getPlanReader());
            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(), rootFragment, queryContext.getSession(), queryContext.getQueryContextInfo());
        planner.visitPhysicalPlan(queryWorkUnit);
        queryWorkUnit.applyPlan(dContext.getPlanReader());
        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) QueryResourceAllocator(org.apache.drill.exec.work.foreman.rm.QueryResourceAllocator)

Example 28 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

the class DrillSeparatePlanningTest method testPlanningNoSplit.

@Test(timeout = 60_000)
public void testPlanningNoSplit() throws Exception {
    final String query = "SELECT dir0, sum(o_totalprice) FROM dfs.`multilevel/json` group by dir0 order by dir0";
    client.alterSession("planner.slice_target", 1);
    try {
        final QueryPlanFragments planFragments = client.planQuery(query);
        assertNotNull(planFragments);
        assertTrue((planFragments.getFragmentsCount() > 1));
        PlanFragment rootFragment = planFragments.getFragments(0);
        assertFalse(rootFragment.getLeafFragment());
        QuerySummary summary = client.queryBuilder().plan(planFragments.getFragmentsList()).run();
        assertEquals(3, summary.recordCount());
    } finally {
        client.resetSession("planner.slice_target");
    }
}
Also used : QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) PlannerTest(org.apache.drill.categories.PlannerTest) SlowTest(org.apache.drill.categories.SlowTest)

Example 29 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

the class DrillSeparatePlanningTest method getResultsHelper.

private int getResultsHelper(final QueryPlanFragments planFragments) throws Exception {
    int totalRows = 0;
    for (PlanFragment fragment : planFragments.getFragmentsList()) {
        DrillbitEndpoint assignedNode = fragment.getAssignment();
        ClientFixture fragmentClient = cluster.client(assignedNode.getAddress(), assignedNode.getUserPort());
        RowSet rowSet = fragmentClient.queryBuilder().sql("select hostname, user_port from sys.drillbits where `current`=true").rowSet();
        assertEquals(1, rowSet.rowCount());
        RowSetReader reader = rowSet.reader();
        assertTrue(reader.next());
        String host = reader.scalar("hostname").getString();
        int port = reader.scalar("user_port").getInt();
        rowSet.clear();
        assertEquals(assignedNode.getAddress(), host);
        assertEquals(assignedNode.getUserPort(), port);
        List<PlanFragment> fragmentList = Lists.newArrayList();
        fragmentList.add(fragment);
        QuerySummary summary = fragmentClient.queryBuilder().plan(fragmentList).run();
        totalRows += summary.recordCount();
        fragmentClient.close();
    }
    return totalRows;
}
Also used : DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) ClientFixture(org.apache.drill.test.ClientFixture) RowSet(org.apache.drill.test.rowSet.RowSet) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment)

Example 30 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

the class DrillSeparatePlanningTest method testMultiMinorFragmentSimpleQuery.

@Test(timeout = 60_000)
public void testMultiMinorFragmentSimpleQuery() throws Exception {
    final String query = "SELECT o_orderkey FROM dfs.`multilevel/json`";
    QueryPlanFragments planFragments = getFragmentsHelper(query);
    assertNotNull(planFragments);
    assertTrue((planFragments.getFragmentsCount() > 1));
    for (PlanFragment planFragment : planFragments.getFragmentsList()) {
        assertTrue(planFragment.getLeafFragment());
    }
    int rowCount = getResultsHelper(planFragments);
    assertEquals(120, rowCount);
}
Also used : QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) PlannerTest(org.apache.drill.categories.PlannerTest) SlowTest(org.apache.drill.categories.SlowTest)

Aggregations

PlanFragment (org.apache.drill.exec.proto.BitControl.PlanFragment)35 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)18 QueryWorkUnit (org.apache.drill.exec.work.QueryWorkUnit)14 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)8 Fragment (org.apache.drill.exec.planner.fragment.Fragment)8 FragmentHandle (org.apache.drill.exec.proto.ExecProtos.FragmentHandle)8 IOException (java.io.IOException)7 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)7 QueryPlanFragments (org.apache.drill.exec.proto.UserProtos.QueryPlanFragments)7 ForemanSetupException (org.apache.drill.exec.work.foreman.ForemanSetupException)7 PlannerTest (org.apache.drill.categories.PlannerTest)6 SlowTest (org.apache.drill.categories.SlowTest)6 ClusterTest (org.apache.drill.test.ClusterTest)6 Test (org.junit.Test)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 MinorFragmentEndpoint (org.apache.drill.exec.physical.MinorFragmentEndpoint)5 IndexedFragmentNode (org.apache.drill.exec.planner.fragment.Materializer.IndexedFragmentNode)5 QueryContextInformation (org.apache.drill.exec.proto.BitControl.QueryContextInformation)5 OptionList (org.apache.drill.exec.server.options.OptionList)5 SimpleParallelizer (org.apache.drill.exec.planner.fragment.SimpleParallelizer)4