Search in sources :

Example 6 with UDFType

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

the class ConstantPropagateProcFactory method isDeterministicUdf.

private static boolean isDeterministicUdf(GenericUDF udf, List<ExprNodeDesc> children) {
    UDFType udfType = udf.getClass().getAnnotation(UDFType.class);
    if (udf instanceof GenericUDFBridge) {
        udfType = ((GenericUDFBridge) udf).getUdfClass().getAnnotation(UDFType.class);
    }
    if (udfType.deterministic() == false) {
        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) UDFType(org.apache.hadoop.hive.ql.udf.UDFType) 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 7 with UDFType

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

the class FunctionRegistry method impliesOrder.

// ---------PTF functions------------
/**
 * Both UDF and UDAF functions can imply order for analytical functions
 *
 * @param functionName
 *          name of function
 * @return true if a GenericUDF or GenericUDAF exists for this name and implyOrder is true, false
 *         otherwise.
 * @throws SemanticException
 */
public static boolean impliesOrder(String functionName) throws SemanticException {
    FunctionInfo info = getFunctionInfo(functionName);
    if (info != null && info.isGenericUDF()) {
        UDFType type = AnnotationUtils.getAnnotation(info.getGenericUDF().getClass(), UDFType.class);
        if (type != null) {
            return type.impliesOrder();
        }
    }
    WindowFunctionInfo windowInfo = getWindowFunctionInfo(functionName);
    if (windowInfo != null) {
        return windowInfo.isImpliesOrder();
    }
    return false;
}
Also used : UDFType(org.apache.hadoop.hive.ql.udf.UDFType)

Example 8 with UDFType

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

the class FunctionRegistry method isDeterministic.

/**
 * Returns whether a GenericUDF is deterministic or not.
 */
public static boolean isDeterministic(GenericUDF genericUDF) {
    if (isStateful(genericUDF)) {
        // the deterministic annotation declares
        return false;
    }
    UDFType genericUDFType = AnnotationUtils.getAnnotation(genericUDF.getClass(), UDFType.class);
    if (genericUDFType != null && genericUDFType.deterministic() == false) {
        return false;
    }
    if (genericUDF instanceof GenericUDFBridge) {
        GenericUDFBridge bridge = (GenericUDFBridge) (genericUDF);
        UDFType bridgeUDFType = AnnotationUtils.getAnnotation(bridge.getUdfClass(), UDFType.class);
        if (bridgeUDFType != null && bridgeUDFType.deterministic() == false) {
            return false;
        }
    }
    if (genericUDF instanceof GenericUDFMacro) {
        GenericUDFMacro macro = (GenericUDFMacro) (genericUDF);
        return macro.isDeterministic();
    }
    return true;
}
Also used : UDFType(org.apache.hadoop.hive.ql.udf.UDFType)

Example 9 with UDFType

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

the class GroupByDesc method isDistinctLike.

/**
 * Checks if this grouping is like distinct, which means that all non-distinct grouping
 * columns behave like they were distinct - for example min and max operators.
 */
public boolean isDistinctLike() {
    List<AggregationDesc> aggregators = getAggregators();
    for (AggregationDesc ad : aggregators) {
        if (!ad.getDistinct()) {
            GenericUDAFEvaluator udafEval = ad.getGenericUDAFEvaluator();
            UDFType annot = AnnotationUtils.getAnnotation(udafEval.getClass(), UDFType.class);
            if (annot == null || !annot.distinctLike()) {
                return false;
            }
        }
    }
    return true;
}
Also used : GenericUDAFEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator) VectorAggregationDesc(org.apache.hadoop.hive.ql.exec.vector.VectorAggregationDesc) UDFType(org.apache.hadoop.hive.ql.udf.UDFType)

Aggregations

UDFType (org.apache.hadoop.hive.ql.udf.UDFType)9 Description (org.apache.hadoop.hive.ql.exec.Description)3 UDF (org.apache.hadoop.hive.ql.exec.UDF)2 GenericUDF (org.apache.hadoop.hive.ql.udf.generic.GenericUDF)2 GenericUDFBridge (org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 SqlOperatorBinding (org.apache.calcite.sql.SqlOperatorBinding)1 OracleSqlOperatorTable (org.apache.calcite.sql.fun.OracleSqlOperatorTable)1 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)1 SqlReturnTypeInference (org.apache.calcite.sql.type.SqlReturnTypeInference)1 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)1 DrillConfig (org.apache.drill.common.config.DrillConfig)1 UserException (org.apache.drill.common.exceptions.UserException)1 FunctionCall (org.apache.drill.common.expression.FunctionCall)1 ClassPathScanner (org.apache.drill.common.scanner.ClassPathScanner)1 ScanResult (org.apache.drill.common.scanner.persistence.ScanResult)1