// should be called after session registry is checked private FunctionInfo registerToSessionRegistry(String qualifiedName, FunctionInfo function) { FunctionInfo ret = null; ClassLoader prev = Utilities.getSessionSpecifiedClassLoader(); try { // Found UDF in metastore - now add it to the function registry // At this point we should add any relevant jars that would be needed for the UDf. FunctionResource[] resources = function.getResources(); try { FunctionTask.addFunctionResources(resources); } catch (Exception e) { LOG.error("Unable to load resources for " + qualifiedName + ":" + e, e); return null; } ClassLoader loader = Utilities.getSessionSpecifiedClassLoader(); Class<?> udfClass = Class.forName(function.getClassName(), true, loader); ret = FunctionRegistry.registerTemporaryUDF(qualifiedName, udfClass, resources); if (ret == null) { LOG.error(function.getClassName() + " is not a valid UDF class and was not registered."); } if (SessionState.get().isHiveServerQuery()) { SessionState.getRegistryForWrite().addToUDFLoaders(loader); } } catch (ClassNotFoundException e) { // Lookup of UDf class failed LOG.error("Unable to load UDF class: " + e); Utilities.restoreSessionSpecifiedClassLoader(prev); } function.shareStateWith(ret); return ret; }
/** * This is called outside of the lock. Some of the methods that are called transitively by this * (e.g. addFunction) will take the lock again and then release it, which is ok. */ private FunctionInfo getFunctionInfoFromMetastoreNoLock(String functionName, HiveConf conf) { try { String[] parts = FunctionUtils.getQualifiedFunctionNameParts(functionName); Function func = Hive.get(conf).getFunction(parts[0].toLowerCase(), parts[1]); if (func == null) { return null; } // Found UDF in metastore - now add it to the function registry. FunctionInfo fi = registerPermanentFunction( functionName, func.getClassName(), true, FunctionTask.toFunctionResource(func.getResourceUris())); if (fi == null) { LOG.error(func.getClassName() + " is not a valid UDF class and was not registered"); return null; } return fi; } catch (Throwable e) { LOG.info("Unable to look up " + functionName + " in metastore", e); } return null; }