重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
hive 0.13開始增加了permanent function;允許用戶自定義的function無需往.hiverc文件中添加create temporary function,提高hive的啟動時間(無需預先執行創建臨時函數命令);并且可以將udf jar包放置于hdfs上,方便管理,無需向hive client端推送udf;但是permanent function有一個問題,就是,需要在function名前添加database名稱,即[database].[function];如果不填寫database,這會取當前database自動補全function。
十多年的常熟網站建設經驗,針對設計、前端、開發、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。網絡營銷推廣的優勢是能夠根據用戶設備顯示端的尺寸不同,自動調整常熟建站的顯示方式,使網站能夠適用不同顯示終端,在瀏覽器中調整網站的寬度,無論在任何一種瀏覽器上瀏覽網站,都能展現優雅布局與設計,從而大程度地提升瀏覽體驗。成都創新互聯從事“常熟網站設計”,“常熟網站推廣”以來,每個客戶項目都認真落實執行。
參照傳統的關系型數據庫,一般存在默認的schema,在搜索function時,優先搜索默認的schema;如iopostgresql的pg_catalog等。因此想著為Hive添加default database這個特性。
添加兩個參數
hive.function.default.function.enabled 默認為:false,表示禁用此特性;設置為true,表示啟動該特性;搜索函數時,優先查找默認database。
hive.function.default.function 默認為: default;當hive.function.default.function.enabled=true時生效;默認函數搜索路徑。
需要添加這個功能,需要了解permanent function在什么時候會用當前database,補全function。
FunctionRegistry.java
private static FunctionInfo getFunctionInfoFromMetastore(String functionName) { FunctionInfo ret = null; try { String dbName; String fName; if (FunctionUtils.isQualifiedFunctionName(functionName)) { String[] parts = FunctionUtils.splitQualifiedFunctionName(functionName); dbName = parts[0]; fName = parts[1]; } else { // otherwise, qualify using current db dbName = SessionState.get().getCurrentDatabase().toLowerCase(); fName = functionName; } // Try looking up function in the metastore HiveConf conf = SessionState.get().getConf(); Function func = Hive.get(conf).getFunction(dbName, fName); if (func != null) { // 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. try { FunctionTask.addFunctionResources(func.getResourceUris()); } catch (Exception e) { LOG.error("Unable to load resources for " + dbName + "." + fName + ":" + e.getMessage(), e); return null; } Class> udfClass = Class.forName(func.getClassName(), true, Utilities.getSessionSpecifiedClassLoader()); if (registerTemporaryFunction(functionName, udfClass)) { ret = mFunctions.get(functionName); } else { LOG.error(func.getClassName() + " is not a valid UDF class and was not registered."); } } } catch (HiveException e) { if (!((e.getCause() != null) && (e.getCause() instanceof MetaException)) && (e.getCause().getCause() != null) && (e.getCause().getCause() instanceof NoSuchObjectException)) { LOG.info("Unable to lookup UDF in metastore: " + e); } } catch (ClassNotFoundException e) { // Lookup of UDf class failed LOG.error("Unable to load UDF class: " + e); } return ret; }
public static String getNormalizedFunctionName(String fn) { // Does the same thing as getFunctionInfo, except for getting the function info. fn = fn.toLowerCase(); return (FunctionUtils.isQualifiedFunctionName(fn) || mFunctions.get(fn) != null) ? fn : FunctionUtils.qualifyFunctionName( fn, SessionState.get().getCurrentDatabase().toLowerCase()); } private staticT getFunctionInfo( Map mFunctions, String functionName) { functionName = functionName.toLowerCase(); T functionInfo = null; if (FunctionUtils.isQualifiedFunctionName(functionName)) { functionInfo = getQualifiedFunctionInfo(mFunctions, functionName); } else { // First try without qualifiers - would resolve builtin/temp functions. // Otherwise try qualifying with current db name. functionInfo = mFunctions.get(functionName); if (functionInfo == null && !FunctionUtils.isQualifiedFunctionName(functionName)) { String qualifiedName = FunctionUtils.qualifyFunctionName(functionName, SessionState.get().getCurrentDatabase().toLowerCase()); functionInfo = getQualifiedFunctionInfo(mFunctions, qualifiedName); } } return functionInfo; }
FunctionUtils.java
public static String[] getQualifiedFunctionNameParts(String name) throws HiveException { if (isQualifiedFunctionName(name)) { return splitQualifiedFunctionName(name); } String dbName = SessionState.get().getCurrentDatabase(); return new String[] { dbName, name }; }
在這些代碼上添加一個判斷hive.function.default.function.enabled是否為true,如果為true,則將默認dbName調整為hive.function.default.function。