diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java index 6f8a8f5504..5e97c742c8 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java @@ -275,9 +275,10 @@ public FunctionInfo registerPermanentFunction(String functionName, if (registerToSession) { String qualifiedName = FunctionUtils.qualifyFunctionName( functionName, SessionState.get().getCurrentDatabase().toLowerCase()); - if (registerToSessionRegistry(qualifiedName, function) != null) { + FunctionInfo newFunction = registerToSessionRegistry(qualifiedName, function); + if (newFunction != null) { addFunction(functionName, function); - return function; + return newFunction; } } else { addFunction(functionName, function); diff --git service/src/test/org/apache/hive/service/cli/TestRegisterPermanentFunction.java service/src/test/org/apache/hive/service/cli/TestRegisterPermanentFunction.java new file mode 100644 index 0000000000..c2449a2f1d --- /dev/null +++ service/src/test/org/apache/hive/service/cli/TestRegisterPermanentFunction.java @@ -0,0 +1,26 @@ +package org.apache.hive.service.cli; + +import org.apache.hadoop.hive.ql.exec.FunctionInfo; +import org.apache.hadoop.hive.ql.exec.Registry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Test RegisterPermanentFunction + * check whether the genericUDF field of returned object is null + * + */ +public class TestRegisterPermanentFunction { + + @Test + public void testRegisterPermanentFunction() throws Exception { + Registry registry = new Registry(true); + FunctionInfo fi = registry.registerPermanentFunction( + "mydb.func1", + "org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper", + true, + null); + assertEquals(fi.getGenericUDF().getUdfName(), "mydb.func1"); + } +}