use of org.apache.hadoop.hive.ql.parse.ASTNode in project SQLWindowing by hbutani.
the class TranslateUtils method buildASTNode.
public static ASTNode buildASTNode(String colName) {
TreeWizard tw = new TreeWizard(adaptor, Windowing2Parser.tokenNames);
Object o = tw.create(sprintf("(TABLEORCOL Identifier[%s])", colName));
return (ASTNode) o;
}
use of org.apache.hadoop.hive.ql.parse.ASTNode in project SQLWindowing by hbutani.
the class WhereTranslation method translate.
public static void translate(QueryDef qDef) throws WindowingException {
QueryTranslationInfo tInfo = qDef.getTranslationInfo();
QuerySpec spec = qDef.getSpec();
ASTNode wExpr = spec.getWhereExpr();
if (wExpr == null)
return;
WhereDef whDef = new WhereDef();
whDef.setExpression(wExpr);
QueryInputDef iDef = qDef.getInput();
InputInfo iInfo = tInfo.getInputInfo(iDef);
ExprNodeDesc exprNode = TranslateUtils.buildExprNode(wExpr, iInfo.getTypeCheckCtx());
ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(tInfo, exprNode);
ObjectInspector oi = TranslateUtils.initExprNodeEvaluator(qDef, exprNode, exprEval, iInfo);
try {
ObjectInspectorConverters.getConverter(oi, PrimitiveObjectInspectorFactory.javaBooleanObjectInspector);
} catch (Throwable t) {
throw new WindowingException("Where Expr must be convertible to a boolean value", t);
}
whDef.setExprNode(exprNode);
whDef.setExprEvaluator(exprEval);
whDef.setOI(oi);
qDef.setWhere(whDef);
}
use of org.apache.hadoop.hive.ql.parse.ASTNode in project SQLWindowing by hbutani.
the class WindowFunctionTranslation method translate.
public static WindowFunctionDef translate(QueryDef qDef, TableFuncDef windowTableFnDef, WindowFunctionSpec wFnSpec) throws WindowingException {
QueryTranslationInfo tInfo = qDef.getTranslationInfo();
InputInfo iInfo = tInfo.getInputInfo(windowTableFnDef.getInput());
WindowFunctionDef wFnDef = new WindowFunctionDef();
wFnDef.setSpec(wFnSpec);
/*
* translate args
*/
ArrayList<ASTNode> args = wFnSpec.getArgs();
if (args != null) {
for (ASTNode expr : args) {
ArgDef argDef = translateWindowFunctionArg(qDef, windowTableFnDef, iInfo, expr);
wFnDef.addArg(argDef);
}
}
if (RANKING_FUNCS.contains(wFnSpec.getName())) {
setupRankingArgs(qDef, windowTableFnDef, wFnDef, wFnSpec);
}
WindowDef wDef = translateWindowSpec(qDef, iInfo, wFnSpec);
wFnDef.setWindow(wDef);
validateWindowDefForWFn(windowTableFnDef, wFnDef);
setupEvaluator(wFnDef);
return wFnDef;
}
use of org.apache.hadoop.hive.ql.parse.ASTNode in project incubator-atlas by apache.
the class HiveASTRewriter method rewrite.
public String rewrite(String sourceQry) throws RewriteException {
String result = sourceQry;
ASTNode tree = null;
try {
ParseDriver pd = new ParseDriver();
tree = pd.parse(sourceQry, queryContext, true);
tree = ParseUtils.findRootNonNullToken(tree);
this.rwCtx = new RewriteContext(sourceQry, tree, queryContext.getTokenRewriteStream());
rewrite(tree);
result = toSQL();
} catch (ParseException e) {
LOG.error("Could not parse the query {} ", sourceQry, e);
throw new RewriteException("Could not parse query : ", e);
}
return result;
}
Aggregations