Search in sources :

Example 11 with GenericUDFBridge

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project drill by apache.

the class HiveFunctionRegistry method matchAndCreateUDFHolder.

private HiveFuncHolder matchAndCreateUDFHolder(String udfName, Class<? extends UDF> udfClazz, MajorType[] argTypes, ObjectInspector[] argOIs) {
    try {
        GenericUDF udfInstance = new GenericUDFBridge(udfName, false, /* is operator */
        udfClazz.getName());
        ObjectInspector returnOI = udfInstance.initialize(argOIs);
        return new HiveFuncHolder(udfName, udfClazz, argTypes, returnOI, Types.optional(ObjectInspectorHelper.getDrillType(returnOI)), nonDeterministicUDFs.contains(udfClazz));
    } catch (Exception e) {
    /*ignore this*/
    }
    return null;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) UserException(org.apache.drill.common.exceptions.UserException)

Example 12 with GenericUDFBridge

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.

the class ConstantPropagateProcFactory method isConstantFoldableUdf.

/**
 * Can the UDF be used for constant folding.
 */
private static boolean isConstantFoldableUdf(GenericUDF udf, List<ExprNodeDesc> children) {
    // Runtime constants + deterministic functions can be folded.
    if (!FunctionRegistry.isConsistentWithinQuery(udf)) {
        if (udf.getClass().equals(GenericUDFUnixTimeStamp.class) && children != null && children.size() > 0) {
            // unix_timestamp is polymorphic (ignore class annotations)
            return true;
        }
        return false;
    }
    // If udf is requiring additional jars, we can't determine the result in
    // compile time.
    String[] files;
    String[] jars;
    if (udf instanceof GenericUDFBridge) {
        GenericUDFBridge bridge = (GenericUDFBridge) udf;
        String udfClassName = bridge.getUdfClassName();
        try {
            UDF udfInternal = (UDF) Class.forName(bridge.getUdfClassName(), true, Utilities.getSessionSpecifiedClassLoader()).newInstance();
            files = udfInternal.getRequiredFiles();
            jars = udfInternal.getRequiredJars();
        } catch (Exception e) {
            LOG.error("The UDF implementation class '" + udfClassName + "' is not present in the class path");
            return false;
        }
    } else {
        files = udf.getRequiredFiles();
        jars = udf.getRequiredJars();
    }
    if (files != null || jars != null) {
        return false;
    }
    return true;
}
Also used : UDF(org.apache.hadoop.hive.ql.exec.UDF) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException)

Example 13 with GenericUDFBridge

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.

the class IndexPredicateAnalyzer method getColumnExpr.

// Check if ExprNodeColumnDesc is wrapped in expr.
// If so, peel off. Otherwise return itself.
private ExprNodeDesc getColumnExpr(ExprNodeDesc expr) {
    if (expr instanceof ExprNodeColumnDesc) {
        return expr;
    }
    ExprNodeGenericFuncDesc funcDesc = null;
    if (expr instanceof ExprNodeGenericFuncDesc) {
        funcDesc = (ExprNodeGenericFuncDesc) expr;
    }
    if (null == funcDesc) {
        return expr;
    }
    GenericUDF udf = funcDesc.getGenericUDF();
    // check if its a simple cast expression.
    if ((udf instanceof GenericUDFBridge || udf instanceof GenericUDFToBinary || udf instanceof GenericUDFToChar || udf instanceof GenericUDFToVarchar || udf instanceof GenericUDFToDecimal || udf instanceof GenericUDFToDate || udf instanceof GenericUDFToUnixTimeStamp || udf instanceof GenericUDFToUtcTimestamp) && funcDesc.getChildren().size() == 1 && funcDesc.getChildren().get(0) instanceof ExprNodeColumnDesc) {
        return expr.getChildren().get(0);
    }
    return expr;
}
Also used : GenericUDFToChar(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToChar) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) GenericUDFToDecimal(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToDecimal) GenericUDFToUnixTimeStamp(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) GenericUDFToBinary(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToBinary) GenericUDFToDate(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToDate) GenericUDFToUtcTimestamp(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUtcTimestamp) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) GenericUDFToVarchar(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToVarchar)

Example 14 with GenericUDFBridge

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.

the class TestVectorizationContext method testTimeStampUdfs.

@Test
public void testTimeStampUdfs() throws HiveException {
    ExprNodeGenericFuncDesc tsFuncExpr = new ExprNodeGenericFuncDesc();
    tsFuncExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
    ExprNodeColumnDesc colDesc1 = new ExprNodeColumnDesc(TypeInfoFactory.timestampTypeInfo, "a", "table", false);
    List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>();
    children.add(colDesc1);
    List<String> columns = new ArrayList<String>();
    columns.add("b");
    columns.add("a");
    VectorizationContext vc = new VectorizationContext("name", columns);
    // UDFYear
    GenericUDFBridge gudfBridge = new GenericUDFBridge("year", false, UDFYear.class.getName());
    tsFuncExpr.setGenericUDF(gudfBridge);
    tsFuncExpr.setChildren(children);
    VectorExpression ve = vc.getVectorExpression(tsFuncExpr);
    Assert.assertEquals(VectorUDFYearTimestamp.class, ve.getClass());
    // GenericUDFToUnixTimeStamp
    GenericUDFToUnixTimeStamp gudf = new GenericUDFToUnixTimeStamp();
    tsFuncExpr.setGenericUDF(gudf);
    tsFuncExpr.setTypeInfo(TypeInfoFactory.longTypeInfo);
    ve = vc.getVectorExpression(tsFuncExpr);
    Assert.assertEquals(VectorUDFUnixTimeStampTimestamp.class, ve.getClass());
}
Also used : ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) ArrayList(java.util.ArrayList) GenericUDFToUnixTimeStamp(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) VectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression) DynamicValueVectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.DynamicValueVectorExpression) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) UDFYear(org.apache.hadoop.hive.ql.udf.UDFYear) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) Test(org.junit.Test)

Example 15 with GenericUDFBridge

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.

the class TestVectorizationContext method testUnaryStringExpressions.

@Test
public void testUnaryStringExpressions() throws HiveException {
    ExprNodeGenericFuncDesc stringUnary = new ExprNodeGenericFuncDesc();
    stringUnary.setTypeInfo(TypeInfoFactory.stringTypeInfo);
    ExprNodeColumnDesc colDesc = new ExprNodeColumnDesc(String.class, "a", "table", false);
    List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>();
    children.add(colDesc);
    stringUnary.setChildren(children);
    List<String> columns = new ArrayList<String>();
    columns.add("b");
    columns.add("a");
    VectorizationContext vc = new VectorizationContext("name", columns);
    GenericUDF stringLower = new GenericUDFLower();
    stringUnary.setGenericUDF(stringLower);
    VectorExpression ve = vc.getVectorExpression(stringUnary);
    assertEquals(StringLower.class, ve.getClass());
    assertEquals(2, ((StringLower) ve).getOutputColumnNum());
    vc = new VectorizationContext("name", columns);
    ExprNodeGenericFuncDesc anotherUnary = new ExprNodeGenericFuncDesc();
    anotherUnary.setTypeInfo(TypeInfoFactory.stringTypeInfo);
    List<ExprNodeDesc> children2 = new ArrayList<ExprNodeDesc>();
    children2.add(stringUnary);
    anotherUnary.setChildren(children2);
    GenericUDFBridge udfbridge = new GenericUDFBridge("ltrim", false, GenericUDFLTrim.class.getName());
    anotherUnary.setGenericUDF(udfbridge);
    ve = vc.getVectorExpression(anotherUnary);
    VectorExpression childVe = ve.getChildExpressions()[0];
    assertEquals(StringLower.class, childVe.getClass());
    assertEquals(2, ((StringLower) childVe).getOutputColumnNum());
    assertEquals(StringLTrim.class, ve.getClass());
    assertEquals(3, ((StringLTrim) ve).getOutputColumnNum());
}
Also used : ArrayList(java.util.ArrayList) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) GenericUDFLower(org.apache.hadoop.hive.ql.udf.generic.GenericUDFLower) GenericUDFLTrim(org.apache.hadoop.hive.ql.udf.generic.GenericUDFLTrim) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) VectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression) DynamicValueVectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.DynamicValueVectorExpression) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) Test(org.junit.Test)

Aggregations

GenericUDFBridge (org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge)18 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)8 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)8 GenericUDF (org.apache.hadoop.hive.ql.udf.generic.GenericUDF)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)6 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)4 UDF (org.apache.hadoop.hive.ql.exec.UDF)3 DynamicValueVectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.DynamicValueVectorExpression)3 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)3 GenericUDFToUnixTimeStamp (org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp)3 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)2 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)2 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)2 GenericUDFToBinary (org.apache.hadoop.hive.ql.udf.generic.GenericUDFToBinary)2 GenericUDFToChar (org.apache.hadoop.hive.ql.udf.generic.GenericUDFToChar)2 GenericUDFToDate (org.apache.hadoop.hive.ql.udf.generic.GenericUDFToDate)2 GenericUDFToDecimal (org.apache.hadoop.hive.ql.udf.generic.GenericUDFToDecimal)2