• 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);

  • 相关阅读:
    UE5.1 透明渲染流程框架图
    Android 腾讯位置服务地图简单使用
    预言机:链接加密世界与现实世界的桥梁
    40+的年龄50W+的年薪,2线城市入职名企,他曾想放弃测试?
    迁移学习(SOT)《Cross-domain Activity Recognition via Substructural Optimal Transport》
    ESP8266-Arduino网络编程实例-Web页面调节LED(基于PWM)
    2022ICPC 网络赛第二场 F Infinity Tree
    CSP-S2019 Day2
    USB设备类型汇总
    蓝桥杯 使用sort排序(c++)
  • 原文地址:https://blog.csdn.net/NeverGiveup54/article/details/126586140