commit 2b234a3fa06aca2392e1ec87fc158531f3a2d602 Author: Abdullah Yousufi Date: Mon Jul 11 14:10:25 2016 -0700 HIVE-14074: RELOAD FUNCTION should update dropped functions diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index 82abd527822dcf976bb3486451672d3dafedafe9..744ca2d4dc91476bdb145b0058988fc1081d3d93 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -233,18 +233,30 @@ private void registerAllFunctionsOnce() throws HiveException { public void reloadFunctions() throws HiveException { + HashSet registryFunctions = new HashSet( + FunctionRegistry.getFunctionNames(".+\\..+")); for (Function function : getAllFunctions()) { String functionName = function.getFunctionName(); try { LOG.info("Registering function " + functionName + " " + function.getClassName()); - FunctionRegistry.registerPermanentFunction(FunctionUtils.qualifyFunctionName( - functionName, function.getDbName()), function.getClassName(), false, + String qualFunc = FunctionUtils.qualifyFunctionName(functionName, function.getDbName()); + FunctionRegistry.registerPermanentFunction(qualFunc, function.getClassName(), false, FunctionTask.toFunctionResource(function.getResourceUris())); + registryFunctions.remove(qualFunc); } catch (Exception e) { LOG.warn("Failed to register persistent function " + functionName + ":" + function.getClassName() + ". Ignore and continue."); } } + // unregister functions from local system registry that are not in getAllFunctions() + for (String functionName : registryFunctions) { + try { + FunctionRegistry.unregisterPermanentFunction(functionName); + } catch (Exception e) { + LOG.warn("Failed to unregister persistent function " + + functionName + "on reload. Ignore and continue."); + } + } } public static Hive get(Configuration c, Class clazz) throws HiveException {