public QueryState transition(Query query, QueryEvent event) {
// increase the count for completed subqueries
query.completedSubQueryCount++;
SubQueryCompletedEvent castEvent = (SubQueryCompletedEvent) event;
ExecutionBlockCursor cursor = query.getExecutionBlockCursor();
MasterPlan masterPlan = query.getPlan();
// if the subquery is succeeded
if (castEvent.getFinalState() == SubQueryState.SUCCEEDED) {
ExecutionBlock nextBlock = cursor.nextBlock();
if (!query.getPlan().isTerminal(nextBlock) || !query.getPlan().isRoot(nextBlock)) {
SubQuery nextSubQuery = new SubQuery(query.context, query.getPlan(), nextBlock, query.sm);
nextSubQuery.setPriority(query.priority--);
query.addSubQuery(nextSubQuery);
nextSubQuery.handle(new SubQueryEvent(nextSubQuery.getId(),
SubQueryEventType.SQ_INIT));
LOG.info("Scheduling SubQuery:" + nextSubQuery.getId());
if(LOG.isDebugEnabled()) {
LOG.debug("Scheduling SubQuery's Priority: " + nextSubQuery.getPriority());
LOG.debug("Scheduling SubQuery's Plan: \n" + nextSubQuery.getBlock().getPlan());
}
return query.checkQueryForCompleted();
} else { // Finish a query
if (query.checkQueryForCompleted() == QueryState.QUERY_SUCCEEDED) {
DataChannel finalChannel = masterPlan.getChannel(castEvent.getExecutionBlockId(), nextBlock.getId());
Path finalOutputDir = commitOutputData(query);
TableDesc finalTableDesc = buildOrUpdateResultTableDesc(query, castEvent.getExecutionBlockId(), finalOutputDir);
QueryContext queryContext = query.context.getQueryContext();
CatalogService catalog = query.context.getQueryMasterContext().getWorkerContext().getCatalog();