• hive2.x中自定义函数未注册上解决


    项目场景:

    1、hive2.x的环境,项目中使用hiveSQL使用自定义函数hiveUDF


    问题描述

    4台hiveserver2节点,其中两台不能执行:自定义函数

    通过show functions like '*udf*';查询没有


    原因分析:

    Reload Function

    Version information

    As of Hive 1.2.0 (HIVE-2573).

    RELOAD (FUNCTIONS|FUNCTION);

    As of HIVE-2573, creating permanent functions in one Hive CLI session may not be reflected in HiveServer2 or other Hive CLI sessions, if they were started before the function was created. Issuing RELOAD FUNCTIONS within a HiveServer2 or HiveCLI session will allow it to pick up any changes to the permanent functions that may have been done by a different HiveCLI session. Due to backward compatibility reasons RELOAD FUNCTION; is also accepted.

    从 HIVE-2573 开始,在一个 Hive CLI 会话中创建永久函数可能不会反映在 HiveServer2 或其他 Hive CLI 会话中,如果它们是在创建函数之前启动的。在 HiveServer2 或 HiveCLI 会话中发出 RELOAD FUNCTIONS 将允许它获取对不同 HiveCLI 会话可能已完成的永久功能的任何更改。由于向后兼容的原因 RELOAD FUNCTION;也被接受。

     官方参考:LanguageManual DDL - Apache Hive - Apache Software Foundation

    以下为hive2.x的reloadFuntions源码

    1. public void reloadFunctions() throws HiveException {
    2. HashSet registryFunctions = new HashSet(
    3. FunctionRegistry.getFunctionNames(".+\\..+"));
    4. for (Function function : getAllFunctions()) {
    5. String functionName = function.getFunctionName();
    6. try {
    7. LOG.info("Registering function " + functionName + " " + function.getClassName());
    8. String qualFunc = FunctionUtils.qualifyFunctionName(functionName, function.getDbName());
    9. FunctionRegistry.registerPermanentFunction(qualFunc, function.getClassName(), false,
    10. FunctionTask.toFunctionResource(function.getResourceUris()));
    11. registryFunctions.remove(qualFunc);
    12. } catch (Exception e) {
    13. LOG.warn("Failed to register persistent function " +
    14. functionName + ":" + function.getClassName() + ". Ignore and continue.");
    15. }
    16. }
    17. // unregister functions from local system registry that are not in getAllFunctions()
    18. for (String functionName : registryFunctions) {
    19. try {
    20. FunctionRegistry.unregisterPermanentFunction(functionName);
    21. } catch (Exception e) {
    22. LOG.warn("Failed to unregister persistent function " +
    23. functionName + "on reload. Ignore and continue.");
    24. }
    25. }
    26. }

    解决方案:

    1、beeline连接到对应hiveserver2节点(注意:不能执行此函数的所有hiveserver2节点)

    2、执行 RELOAD (FUNCTIONS|FUNCTION);

  • 相关阅读:
    【流放之路-装备制作篇】
    configure: error: library ‘crypto‘ is required for OpenSSL
    京东获得店铺的所有商品 API接口分享
    给你一个文件夹,统计其下面的文件数量,包括子文件夹下面的文件
    Openssl 1.1.x android编译
    仅需10秒!ChatGPT轻松画出UML用例图,我却苦战10分钟。
    Nuxt 常见问题与解决方案
    AndroidStudio使用高德地图API获取手机定位
    RMAN-06023
    Eyeshot 2022.3 Fem Released Crack
  • 原文地址:https://blog.csdn.net/NeverGiveup54/article/details/126586140