Search in sources :

Example 1 with QB

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);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) PrintStream(java.io.PrintStream) QB(org.apache.hadoop.hive.ql.parse.QB) TokenRewriteStream(org.antlr.runtime.TokenRewriteStream) OutputStream(java.io.OutputStream) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode)

Example 2 with QB

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;
}
Also used : QB(org.apache.hadoop.hive.ql.parse.QB) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) ParseContext(org.apache.hadoop.hive.ql.parse.ParseContext)

Aggregations

ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)2 QB (org.apache.hadoop.hive.ql.parse.QB)2 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 TokenRewriteStream (org.antlr.runtime.TokenRewriteStream)1 Path (org.apache.hadoop.fs.Path)1 ParseContext (org.apache.hadoop.hive.ql.parse.ParseContext)1