commit b55c8793af1100af930b41b0e9c21544bb8c027f Author: Abdullah Yousufi Date: Tue Jun 21 23:02:55 2016 -0700 HIVE-14074: Update dropped functions with RELOAD FUNCTION 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 2b01fce452dbc3ec4ad1e9e335e5761cb929cb5f..c89e2505fb2672b6750892f2e983042f10c5df41 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,6 +233,10 @@ private void registerAllFunctionsOnce() throws HiveException { public void reloadFunctions() throws HiveException { + String currDBName = this.getDatabaseCurrent().getName(); + String currDBPattern = currDBName.toLowerCase() + "\\..*"; + HashSet registryFunctions = new HashSet( + FunctionRegistry.getFunctionNames(currDBPattern)); for (Function function : getAllFunctions()) { String functionName = function.getFunctionName(); try { @@ -240,11 +244,22 @@ public void reloadFunctions() throws HiveException { FunctionRegistry.registerPermanentFunction(FunctionUtils.qualifyFunctionName( functionName, function.getDbName()), function.getClassName(), false, FunctionTask.toFunctionResource(function.getResourceUris())); + registryFunctions.remove( + FunctionUtils.qualifyFunctionName(functionName, function.getDbName())); } catch (Exception e) { LOG.warn("Failed to register persistent function " + functionName + ":" + function.getClassName() + ". Ignore and continue."); } } + for (String functionName : registryFunctions) { + try { + FunctionRegistry.unregisterPermanentFunction( + FunctionUtils.qualifyFunctionName(functionName, currDBName)); + } 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 {