diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java index 44591842bb..8bf0a9c77d 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java @@ -1678,7 +1678,7 @@ public static void registerTemporaryMacro( } public static FunctionInfo registerPermanentFunction(String functionName, - String className, boolean registerToSession, FunctionResource[] resources) { + String className, boolean registerToSession, FunctionResource[] resources) throws SemanticException { return system.registerPermanentFunction(functionName, className, registerToSession, resources); } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java index 6f8a8f5504..7c0efc407b 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java @@ -269,7 +269,7 @@ public FunctionInfo registerMacro(String macroName, ExprNodeDesc body, } public FunctionInfo registerPermanentFunction(String functionName, - String className, boolean registerToSession, FunctionResource... resources) { + String className, boolean registerToSession, FunctionResource... resources) throws SemanticException { FunctionInfo function = new FunctionInfo(functionName, className, resources); // register to session first for backward compatibility if (registerToSession) { @@ -652,7 +652,7 @@ private FunctionInfo getQualifiedFunctionInfoUnderLock(String qualifiedName) thr } // should be called after session registry is checked - private FunctionInfo registerToSessionRegistry(String qualifiedName, FunctionInfo function) { + private FunctionInfo registerToSessionRegistry(String qualifiedName, FunctionInfo function) throws SemanticException { FunctionInfo ret = null; ClassLoader prev = Utilities.getSessionSpecifiedClassLoader(); try { @@ -682,8 +682,14 @@ private FunctionInfo registerToSessionRegistry(String qualifiedName, FunctionInf // Lookup of UDf class failed LOG.error("Unable to load UDF class: " + e); Utilities.restoreSessionSpecifiedClassLoader(prev); + + throw new SemanticException("Unable to load UDF class: " + e + + "\nPlease ensure that the JAR file containing this class has been properly installed " + + "in the auxiliary directory or was added with ADD JAR command."); + }finally { + function.shareStateWith(ret); } - function.shareStateWith(ret); + return ret; } diff --git a/ql/src/test/queries/clientnegative/create_unknown_permanent_udf.q b/ql/src/test/queries/clientnegative/create_unknown_permanent_udf.q new file mode 100644 index 0000000000..22f3b0aa1d --- /dev/null +++ b/ql/src/test/queries/clientnegative/create_unknown_permanent_udf.q @@ -0,0 +1 @@ +create function my_checksum as 'com.company.proprietary.Checksum'; \ No newline at end of file diff --git a/ql/src/test/results/clientnegative/create_function_nonexistent_class.q.out b/ql/src/test/results/clientnegative/create_function_nonexistent_class.q.out index 77467f66e3..55e66f8ab8 100644 --- a/ql/src/test/results/clientnegative/create_function_nonexistent_class.q.out +++ b/ql/src/test/results/clientnegative/create_function_nonexistent_class.q.out @@ -2,5 +2,5 @@ PREHOOK: query: create function default.badfunc as 'my.nonexistent.class' PREHOOK: type: CREATEFUNCTION PREHOOK: Output: database:default PREHOOK: Output: default.badfunc -Failed to register default.badfunc using class my.nonexistent.class -FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.FunctionTask +FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.FunctionTask. Unable to load UDF class: java.lang.ClassNotFoundException: my.nonexistent.class +Please ensure that the JAR file containing this class has been properly installed in the auxiliary directory or was added with ADD JAR command. diff --git a/ql/src/test/results/clientnegative/create_unknown_permanent_udf.q.out b/ql/src/test/results/clientnegative/create_unknown_permanent_udf.q.out new file mode 100644 index 0000000000..002eab8cf9 --- /dev/null +++ b/ql/src/test/results/clientnegative/create_unknown_permanent_udf.q.out @@ -0,0 +1,6 @@ +PREHOOK: query: create function my_checksum as 'com.company.proprietary.Checksum' +PREHOOK: type: CREATEFUNCTION +PREHOOK: Output: database:default +PREHOOK: Output: default.my_checksum +FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.FunctionTask. Unable to load UDF class: java.lang.ClassNotFoundException: com.company.proprietary.Checksum +Please ensure that the JAR file containing this class has been properly installed in the auxiliary directory or was added with ADD JAR command.