diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionTask.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionTask.java index 075642028c..df3105b49c 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionTask.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionTask.java @@ -207,8 +207,9 @@ private int createPermanentFunction(Hive db, CreateFunctionDesc createFunctionDe try { db.createFunction(func); } catch (Exception e) { - // Addition to metastore failed, remove the function from the registry. - FunctionRegistry.unregisterPermanentFunction(registeredName); + // Addition to metastore failed, remove the function from the registry except if already exists. + if(!(e.getCause() instanceof AlreadyExistsException)) + FunctionRegistry.unregisterPermanentFunction(registeredName); setException(e); LOG.error("Failed to add function " + createFunctionDesc.getFunctionName() + " to the metastore.", e);