文章目录
使用方式
1.在hive中使用udf
1.1使用java代码编写udf
一句话总结:继承UDF类,重写evaluate()方法。
打成jar包之后,要么注册成hive的临时函数,要么注册为永久函数。
hive注册临时函数
hive>add jar /xxx/xxx/your_udf.jar;
hive>CREATE TEMPORARY FUNCTION func_name AS 'com.xxx.xxxx.MyUDF';
hive>list jars;//查看添加好的jar包;
hive>show functions like ’func_*‘; //查看函数
hive注册永久函数
hive>CREATE FUNCTION [db_name].func_name AS 'com.xxx.xxx.MyUDF' USING JAR 'hdfs://hadoop002:9000/xxx/xxx.jar'; //使用时要注意库