Search in sources :

Example 11 with ExprNodeEvaluator

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);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)

Example 12 with ExprNodeEvaluator

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;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc)

Example 13 with ExprNodeEvaluator

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;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) VectorUDAFStdSampTimestamp(org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFStdSampTimestamp) VectorUDAFAvgTimestamp(org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFAvgTimestamp) VectorUDAFVarSampTimestamp(org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFVarSampTimestamp) VectorUDAFVarPopTimestamp(org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFVarPopTimestamp) VectorUDAFStdPopTimestamp(org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFStdPopTimestamp) VectorUDAFMaxTimestamp(org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMaxTimestamp) Timestamp(java.sql.Timestamp) VectorUDAFMinTimestamp(org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMinTimestamp)

Example 14 with ExprNodeEvaluator

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;
}
Also used : ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) GenericUDFLeadLag(org.apache.hadoop.hive.ql.udf.generic.GenericUDFLeadLag) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)

Example 15 with ExprNodeEvaluator

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;
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) UDF(org.apache.hadoop.hive.ql.exec.UDF) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Aggregations

ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)30 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)27 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)18 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)13 ArrayList (java.util.ArrayList)10 WindowingException (com.sap.hadoop.windowing.WindowingException)8 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)8 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)7 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)3 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)3 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)3 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)3 WhereDef (com.sap.hadoop.windowing.query2.definition.WhereDef)2 List (java.util.List)2 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)2 VectorExpressionWriter (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter)2 VectorExpressionWriterFactory (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriterFactory)2 Converter (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 GenericUDFLeadLag (com.sap.hadoop.windowing.functions2.GenericUDFLeadLag)1