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();
}
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;
}
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());
}
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);
}
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);
}
Aggregations