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;
}
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);
}
}
Aggregations