use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.
the class IOUtils method dumpPartition.
public static void dumpPartition(Partition p, PrintStream pw) throws WindowingException {
try {
int sz = p.size();
ObjectInspector OI = p.getSerDe().getObjectInspector();
for (int i = 0; i < sz; i++) {
Object o = p.getAt(i);
o = ObjectInspectorUtils.copyToStandardJavaObject(o, OI);
pw.println(o);
}
} catch (SerDeException se) {
throw new WindowingException(se);
}
}
use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.
the class ParseUtils method parseSelect.
public static SelectSpec parseSelect(String selectExprStr) throws WindowingException {
Windowing2Lexer lexer;
CommonTokenStream tokens;
Windowing2Parser parser = null;
CommonTree t;
CommonTreeNodeStream nodes;
QSpecBuilder2 qSpecBldr = null;
String err;
try {
lexer = new Windowing2Lexer(new ANTLRStringStream(selectExprStr));
tokens = new CommonTokenStream(lexer);
parser = new Windowing2Parser(tokens);
parser.setTreeAdaptor(TranslateUtils.adaptor);
t = (CommonTree) parser.select().getTree();
err = parser.getWindowingParseErrors();
if (err != null) {
throw new WindowingException(err);
}
} catch (WindowingException we) {
throw we;
} catch (Throwable te) {
err = parser.getWindowingParseErrors();
if (err != null) {
throw new WindowingException(err);
}
throw new WindowingException("Parse Error:" + te.toString(), te);
}
TranslateUtils.unescapeStringLiterals((ASTNode) t);
try {
nodes = new CommonTreeNodeStream(t);
nodes.setTokenStream(tokens);
qSpecBldr = new QSpecBuilder2(nodes);
SelectSpec selectSpec = qSpecBldr.select();
err = qSpecBldr.getWindowingParseErrors();
if (err != null) {
throw new WindowingException(err);
}
return selectSpec;
} catch (WindowingException we) {
throw we;
} catch (Throwable te) {
err = qSpecBldr.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 WindowingTableFunction method execute.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute(PartitionIterator<Object> pItr, Partition outP) throws WindowingException {
ArrayList<List<?>> oColumns = new ArrayList<List<?>>();
Partition iPart = pItr.getPartition();
StructObjectInspector inputOI;
try {
inputOI = (StructObjectInspector) iPart.getSerDe().getObjectInspector();
} catch (SerDeException se) {
throw new WindowingException(se);
}
try {
for (WindowFunctionDef wFn : wFnDefs) {
boolean processWindow = wFn.getWindow() != null;
pItr.reset();
if (!processWindow) {
GenericUDAFEvaluator fEval = wFn.getEvaluator();
Object[] args = new Object[wFn.getArgs().size()];
AggregationBuffer aggBuffer = fEval.getNewAggregationBuffer();
while (pItr.hasNext()) {
Object row = pItr.next();
int i = 0;
for (ArgDef arg : wFn.getArgs()) {
args[i++] = arg.getExprEvaluator().evaluate(row);
}
fEval.aggregate(aggBuffer, args);
}
Object out = fEval.evaluate(aggBuffer);
WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFn.getSpec().getName());
if (!wFnInfo.isPivotResult()) {
out = new SameList(iPart.size(), out);
}
oColumns.add((List<?>) out);
} else {
oColumns.add(executeFnwithWindow(getQueryDef(), wFn, iPart));
}
}
for (int i = 0; i < iPart.size(); i++) {
ArrayList oRow = new ArrayList();
Object iRow = iPart.getAt(i);
for (StructField f : inputOI.getAllStructFieldRefs()) {
oRow.add(inputOI.getStructFieldData(iRow, f));
}
for (int j = 0; j < oColumns.size(); j++) {
oRow.add(oColumns.get(j).get(i));
}
outP.append(oRow);
}
} catch (HiveException he) {
throw new WindowingException(he);
}
}
use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.
the class NPath method execute.
@Override
public void execute(PartitionIterator<Object> pItr, Partition outP) throws WindowingException {
while (pItr.hasNext()) {
Object iRow = pItr.next();
SymbolFunctionResult syFnRes = SymbolFunction.match(syFn, iRow, pItr);
if (syFnRes.matches) {
int sz = syFnRes.nextRow - (pItr.getIndex() - 1);
Object selectListInput = NPathUtils.getSelectListInput(iRow, tDef.getInput().getOI(), pItr, sz);
ArrayList<Object> oRow = new ArrayList<Object>();
for (ExprNodeEvaluator resExprEval : resultExprEvals) {
try {
oRow.add(resExprEval.evaluate(selectListInput));
} catch (HiveException he) {
throw new WindowingException(he);
}
}
outP.append(oRow);
}
}
}
use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.
the class ResultExpressionParser method buildSelectListEvaluators.
private void buildSelectListEvaluators() throws WindowingException {
selectListExprEvaluators = new ArrayList<ExprNodeEvaluator>();
selectListExprOIs = new ArrayList<ObjectInspector>();
ArrayList<String> selectListExprNames = new ArrayList<String>();
int i = 0;
Iterator<Object> it = selectSpec.getColumnListAndAlias();
while (it.hasNext()) {
Object[] selectColDetails = (Object[]) it.next();
String selectColName = (String) selectColDetails[1];
ASTNode selectColumnNode = (ASTNode) selectColDetails[2];
ExprNodeDesc selectColumnExprNode = TranslateUtils.buildExprNode(selectColumnNode, selectListInputTypeCheckCtx);
ExprNodeEvaluator selectColumnExprEval = ExprNodeEvaluatorFactory.get(selectColumnExprNode);
ObjectInspector selectColumnOI = null;
try {
selectColumnOI = selectColumnExprEval.initialize(selectListInputOI);
} catch (HiveException he) {
throw new WindowingException(he);
}
selectColName = getColumnName(selectColName, selectColumnExprNode, i);
selectListExprEvaluators.add(selectColumnExprEval);
selectListExprOIs.add(selectColumnOI);
selectListExprNames.add(selectColName);
i++;
}
selectListOutputOI = ObjectInspectorFactory.getStandardStructObjectInspector(selectListExprNames, selectListExprOIs);
}
Aggregations