hive UDF操作
2015-11-07 19:12
134 查看
创建java类(导入对应的依赖包):
public
classHiveHello extendsUDF {
public
Text evaluate(Text in){
Stringresult="helloWorld"+in;
return
new Text(result);
}
}
打成jar:
hive> add jar /script/hive/HelloHive.jar;
创建表:
hive> create table udf_test(name string)row format delimited fields terminated by ' ' stored as textfile;导入数据:
hive> load data local inpath'/script/hive/udf.txt' overwrite into table udf_test;
创建临时函数:
hive> create temporary function syhello as'com.test.udf.HiveHello';
使用函数:
hive> select syhello(name) from udf_test;
使用命令方式来实现上面操作:
[root@hadoop02 hive]# vi execCommend.hql
add jar /script/hive/HelloHive.jar;
drop table IF EXISTS udf_test2;
create table IF NOT EXISTS udf_test2(name string,age int) row formatdelimited fields terminated by ' ' stored as textfile;
load data local inpath'/script/hive/udf_data.txt' overwrite into table udf_test2;
create temporary function sayHello as'com.test.udf.HiveHello';
select sayHello(name),age from udf_test2;
drop temporary function sayHello;
执行上面sql:
[root@hadoop02 bin]# hive -f/script/hive/execCommend.hql ;
Logging initialized using configuration injar:file:/usr/local/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties
Added [/script/hive/HelloHive.jar] to classpath
Added resources: [/script/hive/HelloHive.jar]
OK
Time taken: 4.123 seconds
OK
Time taken: 1.415 seconds
Loading data to table default.udf_test2
Table default.udf_test2 stats: [numFiles=1,numRows=0, totalSize=29, rawDataSize=0]
OK
Time taken: 1.459 seconds
OK
Time taken: 1.187 seconds
OK
helloWorldzhangsan 45
helloWorldlisi 56
helloWorldlidan 18
Time taken: 1.024 seconds, Fetched: 3 row(s)
OK
Time taken: 0.033 seconds
public
classHiveHello extendsUDF {
public
Text evaluate(Text in){
Stringresult="helloWorld"+in;
return
new Text(result);
}
}
打成jar:
hive> add jar /script/hive/HelloHive.jar;
创建表:
hive> create table udf_test(name string)row format delimited fields terminated by ' ' stored as textfile;导入数据:
hive> load data local inpath'/script/hive/udf.txt' overwrite into table udf_test;
创建临时函数:
hive> create temporary function syhello as'com.test.udf.HiveHello';
使用函数:
hive> select syhello(name) from udf_test;
使用命令方式来实现上面操作:
[root@hadoop02 hive]# vi execCommend.hql
add jar /script/hive/HelloHive.jar;
drop table IF EXISTS udf_test2;
create table IF NOT EXISTS udf_test2(name string,age int) row formatdelimited fields terminated by ' ' stored as textfile;
load data local inpath'/script/hive/udf_data.txt' overwrite into table udf_test2;
create temporary function sayHello as'com.test.udf.HiveHello';
select sayHello(name),age from udf_test2;
drop temporary function sayHello;
执行上面sql:
[root@hadoop02 bin]# hive -f/script/hive/execCommend.hql ;
Logging initialized using configuration injar:file:/usr/local/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties
Added [/script/hive/HelloHive.jar] to classpath
Added resources: [/script/hive/HelloHive.jar]
OK
Time taken: 4.123 seconds
OK
Time taken: 1.415 seconds
Loading data to table default.udf_test2
Table default.udf_test2 stats: [numFiles=1,numRows=0, totalSize=29, rawDataSize=0]
OK
Time taken: 1.459 seconds
OK
Time taken: 1.187 seconds
OK
helloWorldzhangsan 45
helloWorldlisi 56
helloWorldlidan 18
Time taken: 1.024 seconds, Fetched: 3 row(s)
OK
Time taken: 0.033 seconds
相关文章推荐
- 两个数的最大公倍数
- hdu5325Crazy Bobo 树形dp
- DDL语句DML语句TCL语句
- 一道题关于构造析构的顺序
- CSS+DIV兼容性问题
- Javabean
- Android.mk文件语法规范及使用模板
- Jdbc练习基础小项目--对个人信息的展示以及增删改查--mvc架构
- HDU 4355 (三分算法基础)
- 几种常用加解密算法简单介绍
- [Android UI] 波浪特效的实现
- C++嵌套类/局部类
- OC ---- 字符串 数组 iOS学习-----细碎知识点总结
- java设计模式
- UVA - 1401 Remember the Word(trie+dp)
- LIRE原理与源码分析(二)——相关接口
- hdu 1297
- Ubuntu 14.04安装Chromium浏览器并添加Flash插件Pepper Flash Player
- 机器学习实战 决策树 算法 笔记
- POJ-2501(用例能过,但一直WA)