You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2019/04/02 03:40:27 UTC

[hive] branch master updated: HIVE-21499 : should not remove the function from registry if create command failed with AlreadyExistsException (Rajkumar Singh via Thejas Nair)

This is an automated email from the ASF dual-hosted git repository.

hashutosh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 5bf5d14  HIVE-21499 : should not remove the function from registry if create command failed with AlreadyExistsException (Rajkumar Singh via Thejas Nair)
5bf5d14 is described below

commit 5bf5d1400e16cc7028fd1c16399e5a74d3fd1b3c
Author: Rajkumar Singh <ra...@hortonworks.com>
AuthorDate: Mon Apr 1 20:39:36 2019 -0700

    HIVE-21499 : should not remove the function from registry if create command failed with AlreadyExistsException (Rajkumar Singh via Thejas Nair)
    
    Signed-off-by: Ashutosh Chauhan <ha...@apache.org>
---
 .../test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java | 13 +++++++++++++
 .../java/org/apache/hadoop/hive/ql/exec/FunctionTask.java   |  6 ++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java
index a2da15f..2e151ec 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java
@@ -1312,6 +1312,19 @@ public class TestJdbcWithMiniHS2 {
     assertEquals(3, res.getInt(1));
     assertFalse("no more results", res.next());
 
+    //try creating same function again which should fail with AlreadyExistsException
+    String createSameFunctionAgain =
+            "CREATE FUNCTION example_add AS '" + testUdfClassName + "' USING JAR '" + jarFilePath + "'";
+    try {
+      stmt.execute(createSameFunctionAgain);
+    }catch (Exception e){
+      assertTrue("recreating same function failed with AlreadyExistsException ", e.getMessage().contains("AlreadyExistsException"));
+    }
+
+    // Call describe to see if function still available in registry
+    res = stmt.executeQuery("DESCRIBE FUNCTION " + testDbName + ".example_add");
+    checkForNotExist(res);
+
     // A new connection should be able to call describe/use function without issue
     Connection conn2 = getConnection(testDbName);
     Statement stmt2 = conn2.createStatement();
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 0756420..2061cf4 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,10 @@ public class FunctionTask extends Task<FunctionWork> {
     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);