zoukankan      html  css  js  c++  java
  • Hive中如何添加自定义UDF函数以及oozie中使用hive的自定义函数

    操作步骤:

    1. 修改.hiverc文件

    在hive的conf文件夹下面,如果没有.hiverc文件,手工自己创建一个。

    参照如下格式添加:

    add jar /usr/local/hive/external_lib/gw-hive-udf.jar;
    create temporary function myexp as 'com.gw.hive.udf.udtf.ExplodeEx';

    第一行为自定义jar包存放的路径。

    第二行为定义的funtion全类名,并且指定函数名为myexp;

    2.上传jar包

    将jar包上次到上面的目录中/usr/local/hive/external_lib

    重启hive就可以使用。

    3.oozie中安装

    如果在oozie中调度hive的脚本时,需要用到该自定义包,则需要单独配置。

    oozie调用时,使用到的依赖都包是保存在hdfs上的。

    如果是hive通用的jar包,则放到hdfs上的oozie指定的hive目录中。

    /user/oozie/share/lib/hive

    如果属于某个程序单独用的依赖jar包,则上传到程序所在目录的lib文件夹中。

    比如:/user/oozie/app/guba_loginlog/lib/,比如

    然后需要使用以下命令刷新oozie的共享包。

    oozie admin -sharelibupdate

    在oozie调用的脚本中同样需要添加:

    create temporary function myexp as 'com.gw.hive.udf.udtf.ExplodeEx';

    190806更新:

    1. 准备条件

    上传文件到hdfs上:

    # 上传文件到hdfs
    hdfs dfs -put encryptAll-1.0.jar /user/hive/udf/

    2.1 hive中添加临时自定义函数

    #临时
    add jar hdfs://ns1/user/hive/udf/udf/encryptAll-1.0.jar;
    或者
    add jar /opt/local/hive/udf/encryptAll-1.0.jar;
    
    
    # 创建函数:
    create temporary function encrypt_all as 'com.test.udf.EncryptAll';
    create temporary function decrypt_all as 'com.test.udf.DecryptAll';

    2.2 hive中添加永久自定义函数

    #永久:
    create function encrypt_all as 'com.test.udf.EncryptAll' using jar 'hdfs://ns1/user/hive/udf/encryptAll-1.0.jar';
    create function decrypt_all as 'com.test.udf.DecryptAll' using jar 'hdfs://ns1/user/hive/udf/encryptAll-1.0.jar';
  • 相关阅读:
    【leetcode】1403. Minimum Subsequence in Non-Increasing Order
    【leetcode】1399. Count Largest Group
    【leetcode】1396. Design Underground System
    【leetcode】1395. Count Number of Teams
    【leetcode】1394. Find Lucky Integer in an Array
    【leetcode】1391. Check if There is a Valid Path in a Grid
    【leetcode】1390. Four Divisors
    【leetcode】1389. Create Target Array in the Given Order
    modelsim仿真基本流程
    Quartus调用MOdelsim仿真过程
  • 原文地址:https://www.cnblogs.com/30go/p/8556143.html
Copyright © 2011-2022 走看看