use of org.apache.hadoop.hive.ql.parse.QB in project hive by apache.
the class ExplainSQRewriteTask method execute.
@Override
public int execute(DriverContext driverContext) {
PrintStream out = null;
try {
Path resFile = new Path(work.getResFile());
OutputStream outS = resFile.getFileSystem(conf).create(resFile);
out = new PrintStream(outS);
QB qb = work.getQb();
TokenRewriteStream stream = work.getCtx().getTokenRewriteStream();
String program = "sq rewrite";
ASTNode ast = work.getAst();
try {
addRewrites(stream, qb, program, out);
out.println("\nRewritten Query:\n" + stream.toString(program, ast.getTokenStartIndex(), ast.getTokenStopIndex()));
} finally {
stream.deleteProgram(program);
}
out.close();
out = null;
return (0);
} catch (Exception e) {
console.printError("Failed with exception " + e.getMessage(), "\n" + StringUtils.stringifyException(e));
return (1);
} finally {
IOUtils.closeStream(out);
}
}
use of org.apache.hadoop.hive.ql.parse.QB in project hive by apache.
the class RewriteParseContextGenerator method doSemanticAnalysis.
/**
* For the input ASTNode tree, perform a semantic analysis and check metadata
* Generate a operator tree and return it.
*
* @param ctx
* @param sem
* @param ast
* @return
* @throws SemanticException
*/
private static Operator<?> doSemanticAnalysis(SemanticAnalyzer sem, ASTNode ast, Context ctx) throws SemanticException {
QB qb = new QB(null, null, false);
ASTNode child = ast;
ParseContext subPCtx = sem.getParseContext();
subPCtx.setContext(ctx);
sem.initParseCtx(subPCtx);
LOG.info("Starting Sub-query Semantic Analysis");
sem.doPhase1(child, qb, sem.initPhase1Ctx(), null);
LOG.info("Completed phase 1 of Sub-query Semantic Analysis");
sem.getMetaData(qb);
LOG.info("Completed getting MetaData in Sub-query Semantic Analysis");
LOG.info("Sub-query Abstract syntax tree: " + ast.toStringTree());
Operator<?> operator = sem.genPlan(qb);
LOG.info("Sub-query Completed plan generation");
return operator;
}
Aggregations