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..37b0b17593 --- /dev/null +++ service/src/test/org/apache/hive/service/cli/TestRegisterPermanentFunction.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hive.service.cli; + +import com.google.common.io.Files; +import org.apache.commons.io.FileUtils; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.ql.exec.FunctionInfo; +import org.apache.hadoop.hive.ql.exec.Registry; +import org.apache.hadoop.hive.ql.session.SessionState; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; + +public class TestRegisterPermanentFunction { + + private File reloadFolder; + + @Before + public void setUp() { + HiveConf conf = new HiveConf(); + String tmp = System.getProperty("java.io.tmpdir"); + File tmpDir = new File(tmp); + if (!tmpDir.exists()) { + tmpDir.mkdir(); + } + String hiveReloadPath = Files.createTempDir().getAbsolutePath(); + // create the reloading folder to place jar files if not exist + reloadFolder = new File(hiveReloadPath); + if (!reloadFolder.exists()) { + reloadFolder.mkdir(); + } + + SessionState.start(conf); + } + + @After + public void tearDown(){ + FileUtils.deleteQuietly(reloadFolder); + } + + /** + * check whether the genericUDF field of returned object is null + * + */ + @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(), + "org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper"); + } +}