summerflowerying / blog-summer

热爱生活 带着翠花看日出
0 stars 0 forks source link

Hive 自定义函数 #70

Open summerflowerying opened 2 years ago

summerflowerying commented 2 years ago

函数创建过程如下 :

    函数名: ua_parse
    #1. 将jar上传到 hdfs
    hadoop fs -put -f ./examples-1.0-SNAPSHOT-shaded.jar /user/hive/udf/examples-1.0-SNAPSHOT-shaded.jar

    #2. 创建永久函数
    create DATABASE IF NOT EXISTS odsdb3;
    CREATE FUNCTION odsdb3.ua_parse AS 'com.test.useragent.hiveusagent.ParseUserAgent_UDF' using jar 'hdfs://hadoop-master:8020/user/hive/udf/examples-1.0-SNAPSHOT-shaded.jar';

    #3. 重新加载函数 
    #集群上有多个hiveServer2实例的时候,在一个hiveServer2实例上注册的UDF在另外一个hiveServer2实例上并不能马上看到新注册的实例,需要重新加载以刷新本实例的函数信息
    reload function;

    #4. 查看函数
    SHOW FUNCTIONS like 'odsdb3.ua_parse';

    #5. 删除函数
    DROP FUNCTION odsdb3.ua_parse;

    #6. 测试
    SELECT odsdb3.ua_parse(t1.hd_user_agent) FROM ods.ods_monitor_log t1;