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);
}
}
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);
}
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);
}
}
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");
}
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);
}
}
Aggregations