Search in sources :

Example 1 with Description

use of org.apache.hadoop.hive.ql.exec.Description in project hive by apache.

the class SqlFunctionConverter method getName.

// TODO: this is not valid. Function names for built-in UDFs are specified in
// FunctionRegistry, and only happen to match annotations. For user UDFs, the
// name is what user specifies at creation time (annotation can be absent,
// different, or duplicate some other function).
private static String getName(GenericUDF hiveUDF) {
    String udfName = null;
    if (hiveUDF instanceof GenericUDFBridge) {
        udfName = ((GenericUDFBridge) hiveUDF).getUdfName();
    } else {
        Class<? extends GenericUDF> udfClass = hiveUDF.getClass();
        Annotation udfAnnotation = udfClass.getAnnotation(Description.class);
        if (udfAnnotation != null && udfAnnotation instanceof Description) {
            Description udfDescription = (Description) udfAnnotation;
            udfName = udfDescription.name();
            if (udfName != null) {
                String[] aliases = udfName.split(",");
                if (aliases.length > 0)
                    udfName = aliases[0];
            }
        }
        if (udfName == null || udfName.isEmpty()) {
            udfName = hiveUDF.getClass().getName();
            int indx = udfName.lastIndexOf(".");
            if (indx >= 0) {
                indx += 1;
                udfName = udfName.substring(indx);
            }
        }
    }
    return udfName;
}
Also used : Description(org.apache.hadoop.hive.ql.exec.Description) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) Annotation(java.lang.annotation.Annotation)

Example 2 with Description

use of org.apache.hadoop.hive.ql.exec.Description 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)

Aggregations

Description (org.apache.hadoop.hive.ql.exec.Description)2 Annotation (java.lang.annotation.Annotation)1 UDFType (org.apache.hadoop.hive.ql.udf.UDFType)1 GenericUDFBridge (org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge)1