Hive编写UDF函数
来源:互联网 发布:饥荒mac版mod 编辑:程序博客网 时间:2024/05/22 02:08
HIVE 编写自定义函数UDF
一 新建JAVA项目 并添加 hive-exec-2.1.0.jar 和hadoop-common-2.7.3.jar
hive-exec-2.1.0.jar 在HIVE安装目录的lib目录下
hadoop-common-2.7.3.jar在hadoop的安装目录下的\share\hadoop\common
二 编一个一个类并继承UDF 并重写evaluate方法
下面以rownum为例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package
com.udf;
import
org.apache.hadoop.hive.ql.exec.UDF;
import
org.apache.hadoop.io.Text;
public
class
RowNumUDF
extends
UDF{
public
static
String signature =
"_"
;
public
static
int
order =
0
;
public
int
evaluate(Text text){
if
(text !=
null
){
//分组排序的依据,列名,通常为主键
String colName = text.toString();
//处理第一条数据
if
(signature ==
"_"
){
//记下分组排序的字段:主键,并将rownum设为1
signature = colName;
order =
1
;
//返回rownum
return
order;
}
else
{
//首先比对是否和上一条主键相同
if
(signature.equals(colName)){
//rownum依次加1
order++;
return
order;
}
else
{
//如果主键改变,将rownum设为1
signature = colName;
order =
1
;
return
order;
}
}
}
else
{
//如果主键为空,则返回-1
return
-
1
;
}
}
}
三 导出位jar包并在HIVE中注册
阅读全文
0 0
- Hive编写UDF函数
- 编写hive udf和使用hive udf:hue的hive界面中使用hive udf函数、oozie使用hive udf函数、hive命令行使用udf函数
- 编写hive udf和使用hive udf:hue的hive界面中使用hive udf函数、oozie使用hive udf函数、hive命令行使用udf函数
- 利用eclipse编写自定义hive udf函数
- 利用eclipse编写自定义hive udf函数
- eclipse下编写hive udf函数
- Hive UDF自定义函数编写小例子
- hive中如何自定义编写UDF函数
- hive UDF编写
- 开发hive UDF函数
- HIVE 自定义函数 UDF
- HIVE UDF函数(一)
- hive的UDF 函数
- hive的UDF 函数
- HIVE UDF函数使用
- 开发hive UDF函数
- Hive UDF函数
- hive 永久udf函数
- (四) tensorflow笔记:常用函数说明
- 边缘化(marginalization )和稀疏化(sparsification)---ceres-solver
- Struts2的运行原理及简要剖析
- 自定义上传组件样式
- ContenType类型大全(包括Office2007文件等问题的解决办法)
- Hive编写UDF函数
- C语言二级指针做函数参数改变该指针的指向
- Android 中的Looper如何实现阻塞与唤醒的
- memcmp的问题
- Spring Boot访问mysql(JPA方式)最简单配置
- python 状态机语句"Python is fun"褒贬义判断的两种实现方式
- Unity NGUI UITexture 图片替换
- Atlantis HDU
- axis2 webservice 接口请求(json对象组装参数请求(用于对象请求)、多个参数请求、阿里巴巴json工具使用)