You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by jo...@apache.org on 2022/02/09 19:01:27 UTC

[impala] 01/02: IMPALA-11109: Catch class loading error for UDFs.

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

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

commit 4bcc29f256acf751d168aacc0c3b14bcbfed5c10
Author: Steve Carlin <sc...@cloudera.com>
AuthorDate: Sat Feb 5 09:03:50 2022 -0800

    IMPALA-11109: Catch class loading error for UDFs.
    
    Fixes regression caused by IMPALA-10997.
    
    If a UDF fails to load, an exception needs to be caught
    and logged or else catalogd will not start up. The
    method HiveLegacyJavaFunction.extract() will catch any hidden
    exception thrown, and rethrow it as a CatalogException. The caller
    already handles the CatalogException and logs the message
    appropriately. The specific "hidden" exception thrown in our
    regression tests was a "ClassNotFoundException", but in case
    there are other exceptions that are thrown, we catch the generic
    "Throwable" exception because the "extract" method should not
    prevent the server from coming up.
    
    Change-Id: I16813209cd4c2367c45e569c2aac13eff7ce2dbf
    Reviewed-on: http://gerrit.cloudera.org:8080/18207
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
    Reviewed-by: Csaba Ringhofer <cs...@cloudera.com>
---
 .../hive/executor/HiveLegacyJavaFunction.java      | 33 ++++++++++++++--------
 .../hive/executor/HiveLegacyJavaFunctionTest.java  |  4 +--
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/fe/src/main/java/org/apache/impala/hive/executor/HiveLegacyJavaFunction.java b/fe/src/main/java/org/apache/impala/hive/executor/HiveLegacyJavaFunction.java
index 6b5773b..e88f166 100644
--- a/fe/src/main/java/org/apache/impala/hive/executor/HiveLegacyJavaFunction.java
+++ b/fe/src/main/java/org/apache/impala/hive/executor/HiveLegacyJavaFunction.java
@@ -147,21 +147,30 @@ public class HiveLegacyJavaFunction implements HiveJavaFunction {
     String jarUri = hiveFn_.getResourceUris().get(0).getUri();
     // Load each method in the UDF class and create the corresponding Impala Function
     // object.
-    for (Method m: UDF_.getClass().getMethods()) {
-      if (m.getName().equals(UDF_FUNCTION_NAME)) {
-        ScalarFunction fn = fromHiveFunction(hiveFn_.getDbName(),
-            hiveFn_.getFunctionName(), hiveFn_.getClassName(),
-            m.getParameterTypes(), m.getReturnType(), jarUri);
-        if (fn != null) {
-          if (!addedSignatures.contains(fn.signatureString())) {
-            result.add(fn);
-            addedSignatures.add(fn.signatureString());
+    try {
+      for (Method m: UDF_.getClass().getMethods()) {
+        if (m.getName().equals(UDF_FUNCTION_NAME)) {
+          ScalarFunction fn = fromHiveFunction(hiveFn_.getDbName(),
+              hiveFn_.getFunctionName(), hiveFn_.getClassName(),
+              m.getParameterTypes(), m.getReturnType(), jarUri);
+          if (fn != null) {
+            if (!addedSignatures.contains(fn.signatureString())) {
+              result.add(fn);
+              addedSignatures.add(fn.signatureString());
+            }
+          } else {
+            LOG.warn("Ignoring incompatible method: " + m.toString() + " during load of "
+                + "Hive UDF:" + hiveFn_.getFunctionName() + " from " + UDF_.getClass());
           }
-        } else {
-          LOG.warn("Ignoring incompatible method: " + m.toString() + " during load of "
-              + "Hive UDF:" + hiveFn_.getFunctionName() + " from " + UDF_.getClass());
         }
       }
+    } catch (Throwable t) {
+      // Catch all runtime exceptions here. One possible runtime exception that can occur
+      // is ClassNotFoundException thrown by UDF_.getClass(). We want to catch all
+      // possible exceptions, mark it as a CatalogException, and let the caller decide on
+      // how to handle it.
+      throw new CatalogException("Error loading function " + hiveFn_.getFunctionName() +
+          ":  " + t);
     }
     if (result.isEmpty()) {
       throw new CatalogException("No compatible function signatures found.");
diff --git a/fe/src/test/java/org/apache/impala/hive/executor/HiveLegacyJavaFunctionTest.java b/fe/src/test/java/org/apache/impala/hive/executor/HiveLegacyJavaFunctionTest.java
index 4aaa88f..4341094 100644
--- a/fe/src/test/java/org/apache/impala/hive/executor/HiveLegacyJavaFunctionTest.java
+++ b/fe/src/test/java/org/apache/impala/hive/executor/HiveLegacyJavaFunctionTest.java
@@ -147,8 +147,8 @@ public class HiveLegacyJavaFunctionTest {
     try {
       testScalar(udfClass, expectedFuncs);
     } catch (CatalogException e) {
-      Assert.assertEquals(e.getMessage(),
-          "No compatible function signatures found.");
+      Assert.assertTrue(e.getMessage().contains(
+          "No compatible function signatures found."));
       return;
     }
     Assert.fail("Extraction should not have succeeded.");