try {
// Send the parser's error messages into a buffer rather than stderr.
ByteArrayOutputStream errBufferStream = new ByteArrayOutputStream();
PrintStream errStream = new PrintStream(errBufferStream);
SQLStatement stmt = mGenerator.parse(query, errStream);
errStream.close();
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);