String errMsg = new String(errBufferStream.toByteArray());
msgBuilder.append(errMsg);
if (null == stmt) {
msgBuilder.append("(Could not parse command)");
return new QuerySubmitResponse(msgBuilder.toString(), null);
}
stmt.accept(new AssignFieldLabelsVisitor());
stmt.accept(new CountStarVisitor()); // Must be after assign labels, before TC.
stmt.accept(new TypeChecker(mRootSymbolTable));
stmt.accept(new ReplaceWindows()); // Must be after TC.
stmt.accept(new JoinKeyVisitor()); // Must be after TC.
stmt.accept(new JoinNameVisitor());
stmt.accept(new IdentifyAggregates()); // Must be after TC.
PlanContext planContext = new PlanContext();
planContext.setConf(planConf);
planContext.setSymbolTable(mRootSymbolTable);
PlanContext retContext = stmt.createExecPlan(planContext);
msgBuilder.append(retContext.getMsgBuilder().toString());
FlowSpecification spec = retContext.getFlowSpec();
if (null != spec) {
spec.setQuery(query);
spec.setConf(planConf);
// Given a flow specification from the AST, run it through
// necessary post-processing and optimization phases.
spec.bfs(new PropagateSchemas());
if (retContext.isExplain()) {
// We just should explain this flow, but not actually add it.
msgBuilder.append("Execution plan:\n");
msgBuilder.append(spec.toString());
msgBuilder.append("\n");
} else {
flowId = addFlow(spec);
}
}
} catch (VisitException ve) {
msgBuilder.append("Error processing command: " + ve.getMessage());
} catch (RecognitionException re) {
msgBuilder.append("Error parsing command: " + re.getMessage());
} catch (DAGOperatorException doe) {
msgBuilder.append("Error processing plan: " + doe.getMessage());
}
return new QuerySubmitResponse(msgBuilder.toString(), flowId);
}