Search in sources :

Example 11 with QueryPlanFragments

use of org.apache.drill.exec.proto.UserProtos.QueryPlanFragments in project drill by apache.

the class PlanSplitter method planFragments.

/**
 * Method to plan the query and return list of fragments
 * it will return query plan "as is" or split plans based on the req setting: split_plan
 * @param dContext
 * @param queryId
 * @param req
 * @param connection
 * @return
 */
public QueryPlanFragments planFragments(DrillbitContext dContext, QueryId queryId, GetQueryPlanFragments req, UserClientConnection connection) {
    QueryPlanFragments.Builder responseBuilder = QueryPlanFragments.newBuilder();
    final QueryContext queryContext = new QueryContext(connection.getSession(), dContext, queryId);
    responseBuilder.setQueryId(queryId);
    try {
        responseBuilder.addAllFragments(getFragments(dContext, req, queryContext, queryId));
        responseBuilder.setStatus(QueryState.COMPLETED);
    } catch (Exception e) {
        final String errorMessage = String.format("Failed to produce PlanFragments for query id \"%s\" with " + "request to %s plan", queryId, (req.getSplitPlan() ? "split" : "no split"));
        DrillPBError error = DrillPBError.newBuilder().setMessage(errorMessage).setErrorType(DrillPBError.ErrorType.PLAN).build();
        responseBuilder.setStatus(QueryState.FAILED);
        responseBuilder.setError(error);
    }
    try {
        queryContext.close();
    } catch (Exception e) {
        logger.error("Error closing QueryContext when getting plan fragments for query {}.", QueryIdHelper.getQueryId(queryId), e);
    }
    return responseBuilder.build();
}
Also used : DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) GetQueryPlanFragments(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) QueryContext(org.apache.drill.exec.ops.QueryContext)

Example 12 with QueryPlanFragments

use of org.apache.drill.exec.proto.UserProtos.QueryPlanFragments in project drill by apache.

the class UserWorker method getQueryPlan.

public QueryPlanFragments getQueryPlan(UserClientConnection connection, GetQueryPlanFragments req) {
    final QueryId queryId = queryIdGenerator();
    final QueryPlanFragments qPlanFragments = new PlanSplitter().planFragments(bee.getContext(), queryId, req, connection);
    return qPlanFragments;
}
Also used : QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) GetQueryPlanFragments(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId)

Example 13 with QueryPlanFragments

use of org.apache.drill.exec.proto.UserProtos.QueryPlanFragments in project drill by apache.

the class DrillSeparatePlanningTest method testSingleFragmentQuery.

@Test(timeout = 60_000)
public void testSingleFragmentQuery() throws Exception {
    final String query = "SELECT * FROM cp.`employee.json` where employee_id > 1 and employee_id < 1000";
    QueryPlanFragments planFragments = getFragmentsHelper(query);
    assertNotNull(planFragments);
    assertEquals(1, planFragments.getFragmentsCount());
    assertTrue(planFragments.getFragments(0).getLeafFragment());
    QuerySummary summary = client.queryBuilder().plan(planFragments.getFragmentsList()).run();
    assertEquals(997, summary.recordCount());
}
Also used : QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) PlannerTest(org.apache.drill.categories.PlannerTest) SlowTest(org.apache.drill.categories.SlowTest)

Example 14 with QueryPlanFragments

use of org.apache.drill.exec.proto.UserProtos.QueryPlanFragments in project drill by apache.

the class DrillSeparatePlanningTest method testPlanningNegative.

@Test(timeout = 60_000)
public void testPlanningNegative() throws Exception {
    final String query = "SELECT dir0, sum(o_totalprice) FROM dfs.`multilevel/json` group by dir0 order by dir0";
    // LOGICAL is not supported
    final QueryPlanFragments planFragments = client.planQuery(QueryType.LOGICAL, query, false);
    assertNotNull(planFragments);
    assertNotNull(planFragments.getError());
    assertTrue(planFragments.getFragmentsCount() == 0);
}
Also used : QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) PlannerTest(org.apache.drill.categories.PlannerTest) SlowTest(org.apache.drill.categories.SlowTest)

Example 15 with QueryPlanFragments

use of org.apache.drill.exec.proto.UserProtos.QueryPlanFragments in project drill by apache.

the class DrillSeparatePlanningTest method testMultiMinorFragmentComplexQuery.

@Test(timeout = 60_000)
public void testMultiMinorFragmentComplexQuery() throws Exception {
    final String query = "SELECT dir0, sum(o_totalprice) FROM dfs.`multilevel/json` group by dir0 order by dir0";
    QueryPlanFragments planFragments = getFragmentsHelper(query);
    assertNotNull(planFragments);
    assertTrue((planFragments.getFragmentsCount() > 1));
    for (PlanFragment planFragment : planFragments.getFragmentsList()) {
        assertTrue(planFragment.getLeafFragment());
    }
    int rowCount = getResultsHelper(planFragments);
    assertEquals(8, 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

QueryPlanFragments (org.apache.drill.exec.proto.UserProtos.QueryPlanFragments)15 PlannerTest (org.apache.drill.categories.PlannerTest)10 SlowTest (org.apache.drill.categories.SlowTest)10 ClusterTest (org.apache.drill.test.ClusterTest)10 Test (org.junit.Test)10 PlanFragment (org.apache.drill.exec.proto.BitControl.PlanFragment)7 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)4 GetQueryPlanFragments (org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments)4 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)4 QueryContext (org.apache.drill.exec.ops.QueryContext)2 DrillPBError (org.apache.drill.exec.proto.UserBitShared.DrillPBError)2 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)2 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)1