Search in sources :

Example 1 with UDFType

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

the class HiveFunctionRegistry method register.

private <C, I> void register(Class<? extends I> clazz, ArrayListMultimap<String, Class<? extends I>> methods) {
    Description desc = clazz.getAnnotation(Description.class);
    String[] names;
    if (desc != null) {
        names = desc.name().split(",");
        for (int i = 0; i < names.length; i++) {
            names[i] = names[i].trim();
        }
    } else {
        names = new String[] { clazz.getName().replace('.', '_') };
    }
    UDFType type = clazz.getAnnotation(UDFType.class);
    if (type != null && !type.deterministic()) {
        nonDeterministicUDFs.add(clazz);
    }
    for (int i = 0; i < names.length; i++) {
        methods.put(names[i].toLowerCase(), clazz);
    }
}
Also used : Description(org.apache.hadoop.hive.ql.exec.Description) UDFType(org.apache.hadoop.hive.ql.udf.UDFType)

Example 2 with UDFType

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

the class HiveFunctionRegistry method register.

private <C, I> void register(Class<? extends I> clazz, ArrayListMultimap<String, Class<? extends I>> methods) {
    Description desc = clazz.getAnnotation(Description.class);
    String[] names;
    if (desc != null) {
        names = desc.name().split(",");
        for (int i = 0; i < names.length; i++) {
            names[i] = names[i].trim();
        }
    } else {
        names = new String[] { clazz.getName().replace('.', '_') };
    }
    UDFType type = clazz.getAnnotation(UDFType.class);
    if (type != null && !type.deterministic()) {
        nonDeterministicUDFs.add(clazz);
    }
    for (int i = 0; i < names.length; i++) {
        methods.put(names[i].toLowerCase(), clazz);
    }
}
Also used : Description(org.apache.hadoop.hive.ql.exec.Description) UDFType(org.apache.hadoop.hive.ql.udf.UDFType)

Example 3 with UDFType

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

the class HiveFunctionRegistry method register.

private <I> void register(Class<? extends I> clazz, Multimap<String, Class<? extends I>> methods) {
    Description desc = clazz.getAnnotation(Description.class);
    Stream<String> namesStream;
    if (desc != null) {
        namesStream = Stream.of(desc.name().split(",")).map(String::trim);
    } else {
        namesStream = Stream.of(clazz).map(Class::getName).map(name -> name.replace('.', '_'));
    }
    // Checks specified array of function names whether they should be replaced
    // using FUNCTION_REPLACE_MAP map.
    namesStream.map(String::toLowerCase).map(functionName -> FUNCTION_REPLACE_MAP.getOrDefault(functionName, functionName)).forEach(name -> methods.put(name, clazz));
    UDFType type = clazz.getAnnotation(UDFType.class);
    if (type != null && !type.deterministic()) {
        nonDeterministicUDFs.add(clazz);
    }
}
Also used : UDFType(org.apache.hadoop.hive.ql.udf.UDFType) ObjectInspectorHelper(org.apache.drill.exec.expr.fn.impl.hive.ObjectInspectorHelper) ClassPathScanner(org.apache.drill.common.scanner.ClassPathScanner) UserException(org.apache.drill.common.exceptions.UserException) LoggerFactory(org.slf4j.LoggerFactory) Types(org.apache.drill.common.types.Types) Sets(org.apache.drill.shaded.guava.com.google.common.collect.Sets) Description(org.apache.hadoop.hive.ql.exec.Description) ArrayListMultimap(org.apache.drill.shaded.guava.com.google.common.collect.ArrayListMultimap) HashSet(java.util.HashSet) UDF(org.apache.hadoop.hive.ql.exec.UDF) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) FunctionCall(org.apache.drill.common.expression.FunctionCall) Map(java.util.Map) HiveUDFOperatorWithoutInference(org.apache.drill.exec.planner.sql.HiveUDFOperatorWithoutInference) DrillOperatorTable(org.apache.drill.exec.planner.sql.DrillOperatorTable) Multimap(org.apache.drill.shaded.guava.com.google.common.collect.Multimap) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) HiveUDFOperator(org.apache.drill.exec.planner.sql.HiveUDFOperator) SqlOperatorBinding(org.apache.calcite.sql.SqlOperatorBinding) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) RelDataType(org.apache.calcite.rel.type.RelDataType) Logger(org.slf4j.Logger) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) TypeInferenceUtils(org.apache.drill.exec.planner.sql.TypeInferenceUtils) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) Set(java.util.Set) SqlReturnTypeInference(org.apache.calcite.sql.type.SqlReturnTypeInference) TypeProtos(org.apache.drill.common.types.TypeProtos) Stream(java.util.stream.Stream) DrillConfig(org.apache.drill.common.config.DrillConfig) ImmutableMap(org.apache.drill.shaded.guava.com.google.common.collect.ImmutableMap) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) OracleSqlOperatorTable(org.apache.calcite.sql.fun.OracleSqlOperatorTable) ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) Description(org.apache.hadoop.hive.ql.exec.Description) UDFType(org.apache.hadoop.hive.ql.udf.UDFType)

Example 4 with UDFType

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

the class FunctionRegistry method isRuntimeConstant.

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

Example 5 with UDFType

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

the class FunctionRegistry method isStateful.

/**
 * Returns whether a GenericUDF is stateful or not.
 */
public static boolean isStateful(GenericUDF genericUDF) {
    UDFType genericUDFType = AnnotationUtils.getAnnotation(genericUDF.getClass(), UDFType.class);
    if (genericUDFType != null && genericUDFType.stateful()) {
        return true;
    }
    if (genericUDF instanceof GenericUDFBridge) {
        GenericUDFBridge bridge = (GenericUDFBridge) genericUDF;
        UDFType bridgeUDFType = AnnotationUtils.getAnnotation(bridge.getUdfClass(), UDFType.class);
        if (bridgeUDFType != null && bridgeUDFType.stateful()) {
            return true;
        }
    }
    if (genericUDF instanceof GenericUDFMacro) {
        GenericUDFMacro macro = (GenericUDFMacro) (genericUDF);
        return macro.isStateful();
    }
    return false;
}
Also used : 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