use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project SQLWindowing by hbutani.
the class QueryDefDeserializer method visit.
/*
* Recreate ExprNodeEvaluator, OI using InputInfo of first InputDef in
* chain.
*/
@Override
public void visit(WhereDef where) throws WindowingException {
ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(tInfo, where.getExprNode());
ObjectInspector oi = TranslateUtils.initExprNodeEvaluator(qDef, where.getExprNode(), exprEval, inputInfo);
where.setExprEvaluator(exprEval);
where.setOI(oi);
}
use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project SQLWindowing by hbutani.
the class OutputTranslation method translateSelectExpr.
public static ColumnDef translateSelectExpr(QueryDef qDef, InputInfo iInfo, int colIdx, String alias, ASTNode expr) throws WindowingException {
ColumnDef cDef = new ColumnDef((ColumnSpec) null);
ExprNodeDesc exprNode = TranslateUtils.buildExprNode(expr, iInfo.getTypeCheckCtx());
ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(qDef.getTranslationInfo(), exprNode);
ObjectInspector oi = TranslateUtils.initExprNodeEvaluator(qDef, exprNode, exprEval, iInfo);
cDef.setExpression(expr);
cDef.setExprNode(exprNode);
cDef.setExprEvaluator(exprEval);
cDef.setOI(oi);
cDef.setAlias(getAlias(alias, expr, colIdx));
return cDef;
}
use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project hive by apache.
the class VectorizationContext method evaluateCastToTimestamp.
private Timestamp evaluateCastToTimestamp(ExprNodeDesc expr) throws HiveException {
ExprNodeGenericFuncDesc expr2 = (ExprNodeGenericFuncDesc) expr;
ExprNodeEvaluator evaluator = ExprNodeEvaluatorFactory.get(expr2);
ObjectInspector output = evaluator.initialize(null);
Object constant = evaluator.evaluate(null);
Object java = ObjectInspectorUtils.copyToStandardJavaObject(constant, output);
if (!(java instanceof Timestamp)) {
throw new HiveException("Udf: failed to convert to timestamp");
}
Timestamp ts = (Timestamp) java;
return ts;
}
use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project hive by apache.
the class PTFDeserializer method initExprNodeEvaluator.
private ObjectInspector initExprNodeEvaluator(ExprNodeEvaluator exprEval, ExprNodeDesc exprNode, ShapeDetails inpShape) throws HiveException {
ObjectInspector outOI;
outOI = exprEval.initialize(inpShape.getOI());
/*
* if there are any LeadLag functions in this Expression Tree: - setup a
* duplicate Evaluator for the 1st arg of the LLFuncDesc - initialize it
* using the InputInfo provided for this Expr tree - set the duplicate
* evaluator on the LLUDF instance.
*/
List<ExprNodeGenericFuncDesc> llFuncExprs = llInfo.getLLFuncExprsInTopExpr(exprNode);
if (llFuncExprs != null) {
for (ExprNodeGenericFuncDesc llFuncExpr : llFuncExprs) {
ExprNodeDesc firstArg = llFuncExpr.getChildren().get(0);
ExprNodeEvaluator dupExprEval = WindowingExprNodeEvaluatorFactory.get(llInfo, firstArg);
dupExprEval.initialize(inpShape.getOI());
GenericUDFLeadLag llFn = (GenericUDFLeadLag) llFuncExpr.getGenericUDF();
llFn.setExprEvaluator(dupExprEval);
}
}
return outOI;
}
use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project hive by apache.
the class ExprNodeDescUtils method foldConstant.
private static ExprNodeConstantDesc foldConstant(ExprNodeGenericFuncDesc func) {
GenericUDF udf = func.getGenericUDF();
if (!FunctionRegistry.isDeterministic(udf) || FunctionRegistry.isStateful(udf)) {
return null;
}
try {
// resources may not be available at compile time.
if (udf instanceof GenericUDFBridge) {
UDF internal = ReflectionUtils.newInstance(((GenericUDFBridge) udf).getUdfClass(), null);
if (internal.getRequiredFiles() != null || internal.getRequiredJars() != null) {
return null;
}
} else {
if (udf.getRequiredFiles() != null || udf.getRequiredJars() != null) {
return null;
}
}
if (func.getChildren() != null) {
for (ExprNodeDesc child : func.getChildren()) {
if (child instanceof ExprNodeConstantDesc) {
continue;
}
if (child instanceof ExprNodeGenericFuncDesc) {
if (foldConstant((ExprNodeGenericFuncDesc) child) != null) {
continue;
}
}
return null;
}
}
ExprNodeEvaluator evaluator = ExprNodeEvaluatorFactory.get(func);
ObjectInspector output = evaluator.initialize(null);
Object constant = evaluator.evaluate(null);
Object java = ObjectInspectorUtils.copyToStandardJavaObject(constant, output);
return new ExprNodeConstantDesc(java);
} catch (Exception e) {
return null;
}
}
Aggregations