Search in sources :

Example 16 with WindowingException

use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.

the class WindowingShell method checkQuery.

public void checkQuery(String query) throws WindowingException {
    Windowing2Lexer lexer;
    CommonTokenStream tokens;
    Windowing2Parser parser = null;
    @SuppressWarnings("unused") CommonTree t;
    //		CommonTreeNodeStream nodes;
    String err;
    try {
        lexer = new Windowing2Lexer(new ANTLRStringStream(query));
        tokens = new CommonTokenStream(lexer);
        parser = new Windowing2Parser(tokens);
        parser.setTreeAdaptor(TranslateUtils.adaptor);
        t = (CommonTree) parser.query().getTree();
        err = parser.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
    } catch (Throwable te) {
        err = parser.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
        throw new WindowingException("Parse Error:" + te.toString(), te);
    }
}
Also used : Windowing2Lexer(com.sap.hadoop.windowing.parser.Windowing2Lexer) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) Windowing2Parser(com.sap.hadoop.windowing.parser.Windowing2Parser) WindowingException(com.sap.hadoop.windowing.WindowingException)

Example 17 with WindowingException

use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.

the class WindowingShell method loadToOutputTable.

protected void loadToOutputTable(QueryDef qry) throws WindowingException {
    //LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename [PARTITION (partcol1=val1, partcol2=val2 ...)]
    String loadCmd = sprintf("load data inpath '%s'", qry.getOutput().getSpec().getPath());
    if (qry.getOutput().getSpec().isOverwriteHiveTable()) {
        loadCmd += " OVERWRITE";
    }
    loadCmd += sprintf(" INTO TABLE %s", qry.getOutput().getSpec().getHiveTable());
    if (qry.getOutput().getSpec().getPartitionClause() != null) {
        loadCmd += sprintf(" PARTITION %s", qry.getOutput().getSpec().getPartitionClause());
    }
    /*
		 * delete the _SUCCESS file; comes in the way of doing a load for RcFiles.
		 * also delete _logs directory
		 */
    if (true) {
        try {
            FileSystem fs = FileSystem.get(URI.create(qry.getOutput().getSpec().getPath()), cfg);
            Path p = new Path(qry.getOutput().getSpec().getPath(), "_SUCCESS");
            if (fs.exists(p)) {
                fs.delete(p, false);
            }
            p = new Path(qry.getOutput().getSpec().getPath(), "_logs");
            if (fs.exists(p)) {
                fs.delete(p, true);
            }
        } catch (IOException ioe) {
            throw new WindowingException(ioe);
        }
    }
    hiveQryExec.executeHiveQuery(loadCmd);
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) WindowingException(com.sap.hadoop.windowing.WindowingException) IOException(java.io.IOException)

Example 18 with WindowingException

use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.

the class MRExecutor method execute.

/* 
	 * Create a MapRedWork object and an operator tree 
	 * for processing queries with table functions. 
	 * Execute the plan defined in the MapRedWork using 
	 * the Hive runtime environment. 
	 */
@Override
public void execute(QueryDef qdef, WindowingShell wShell) throws WindowingException {
    deleteQueryOutputDir(qdef);
    MapredWork mr = PlanUtils.getMapRedWork();
    try {
        createOperatorTree(qdef, mr);
        executePlan(mr, wShell.getCfg());
    } catch (SemanticException se) {
        throw new WindowingException(se);
    } catch (Exception e) {
        throw new WindowingException(e);
    }
}
Also used : MapredWork(org.apache.hadoop.hive.ql.plan.MapredWork) WindowingException(com.sap.hadoop.windowing.WindowingException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) IOException(java.io.IOException) WindowingException(com.sap.hadoop.windowing.WindowingException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 19 with WindowingException

use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.

the class MRExecutor method executePlan.

/**
	 * Invoke the MapRedTask and set the MapRedWork 
	 * query plan to be used for execution.  
	 * MapRedTask (an extension to the ExecDriver) is 
	 * used to execute the query plan on Hadoop.
	 * @param mr
	 * @param hiveConf
	 * @throws Exception
	 */
private void executePlan(MapredWork mr, HiveConf hiveConf) throws Exception {
    MapRedTask mrtask = new MapRedTask();
    DriverContext dctx = new DriverContext();
    mrtask.setWork(mr);
    mrtask.initialize(hiveConf, null, dctx);
    int exitVal = mrtask.execute(dctx);
    if (exitVal != 0) {
        System.out.println("Test execution failed with exit status: " + exitVal);
        throw new WindowingException("Test execution failed with exit status: " + exitVal);
    } else
        System.out.println("Test execution completed successfully");
}
Also used : MapRedTask(org.apache.hadoop.hive.ql.exec.MapRedTask) DriverContext(org.apache.hadoop.hive.ql.DriverContext) WindowingException(com.sap.hadoop.windowing.WindowingException)

Example 20 with WindowingException

use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.

the class MRExecutor method deleteQueryOutputDir.

static void deleteQueryOutputDir(QueryDef qDef) throws WindowingException {
    try {
        String outputPath = qDef.getOutput().getSpec().getPath();
        FileSystem fs = FileSystem.get(URI.create(outputPath), qDef.getTranslationInfo().getHiveCfg());
        Path p = new Path(outputPath);
        if (fs.exists(p)) {
            fs.delete(p, true);
        }
    } catch (IOException ie) {
        throw new WindowingException(ie);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) WindowingException(com.sap.hadoop.windowing.WindowingException) IOException(java.io.IOException)

Aggregations

WindowingException (com.sap.hadoop.windowing.WindowingException)62 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)18 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)11 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)10 IOException (java.io.IOException)9 SerDe (org.apache.hadoop.hive.serde2.SerDe)9 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)8 ArrayList (java.util.ArrayList)7 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)7 HiveMetaStoreClient (org.apache.hadoop.hive.metastore.HiveMetaStoreClient)6 Properties (java.util.Properties)5 Path (org.apache.hadoop.fs.Path)5 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)5 Table (org.apache.hadoop.hive.metastore.api.Table)5 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)5 Writable (org.apache.hadoop.io.Writable)5 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)4 HiveConf (org.apache.hadoop.hive.conf.HiveConf)4 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)4 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)3