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

  • 相关阅读:
    HTML网页设计——轮滑运动体育类人物介绍主题12页面毕业设计网页
    linux安装git
    大数据学习1.0-目录
    C#.Net筑基-集合知识全解
    数学建模——统计回归模型
    三只松鼠,“跑”不动了?
    教师办公实用小程序有哪些
    [附源码]JAVA毕业设计昆明市人民医院血库管理系统(系统+LW)
    友情提示:lazarus的tsortgrid.autofillcolumns存在BUG
    技术问题分析和解决汇总,持续维护
  • 原文地址:https://blog.csdn.net/NeverGiveup54/article/details/126586140