博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
编写hive udf函数
阅读量:6202 次
发布时间:2019-06-21

本文共 2260 字,大约阅读时间需要 7 分钟。

大写转小写

package com.afan;

import org.apache.hadoop.hive.ql.exec.UDF;

import org.apache.hadoop.io.Text;


public class UDFLower extends UDF{

    public Text evaluate(final Text s){

        if (null == s){

            return null;

        }

        return new Text(s.toString().toLowerCase());

    }

}


1、加载udf jar包

afan@ubuntu:/usr/local/hadoop/hive$ bin/hive

Hive history file=/tmp/afan/hive_job_log_afan_201105150623_175667077.txt

hive> add jar udf_hive.jar;

Added udf_hive.jar to class path

Added resource: udf_hive.jar

2、创建udf函数

hive> create temporary function my_lower as 'com.afan.UDFLower';

OK

Time taken: 0.253 seconds

3、创建测试数据

hive> create table dual (info string);

OK

Time taken: 0.178 seconds

hive> load data local inpath 'data.txt' into table dual;

Copying data from file:/usr/local/hadoop/hive/data.txt

Copying file: file:/usr/local/hadoop/hive/data.txt

Loading data to table default.dual

OK

Time taken: 0.377 seconds

hive> select info from dual;

Total MapReduce jobs = 1

Launching Job 1 out of 1

Number of reduce tasks is set to 0 since there's no reduce operator

Starting Job = job_201105150525_0003, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job_201105150525_0003

Kill Command = /usr/local/hadoop/bin/../bin/hadoop job  -Dmapred.job.tracker=localhost:9001 -kill job_201105150525_0003

2011-05-15 06:46:05,459 Stage-1 map = 0%,  reduce = 0%

2011-05-15 06:46:10,905 Stage-1 map = 100%,  reduce = 0%

2011-05-15 06:46:13,963 Stage-1 map = 100%,  reduce = 100%

Ended Job = job_201105150525_0003

OK

WHO

AM

I

HELLO

worLd


Time taken: 14.874 seconds

4、使用udf函数

hive> select my_lower(info) from dual;

Total MapReduce jobs = 1

Launching Job 1 out of 1

Number of reduce tasks is set to 0 since there's no reduce operator

Starting Job = job_201105150525_0002, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job_201105150525_0002

Kill Command = /usr/local/hadoop/bin/../bin/hadoop job  -Dmapred.job.tracker=localhost:9001 -kill job_201105150525_0002

2011-05-15 06:43:26,100 Stage-1 map = 0%,  reduce = 0%

2011-05-15 06:43:34,364 Stage-1 map = 100%,  reduce = 0%

2011-05-15 06:43:37,484 Stage-1 map = 100%,  reduce = 100%

Ended Job = job_201105150525_0002

OK

who

am

i

hello

world


Time taken: 20.834 seconds
本文转自 SimplePoint 51CTO博客,原文链接:http://blog.51cto.com/2226894115/1897838,如需转载请自行联系原作者
你可能感兴趣的文章
intelliJ IDEA 中快速定位当前文件路径
查看>>
do not kown
查看>>
(转)详解Javascript 中的this指针
查看>>
2017 多校1 I Curse Myself
查看>>
***文件上传控件bootstrap-fileinput的使用和参数配置说明
查看>>
2016国产开源软件TOP100(Q1)
查看>>
二叉搜索树的最近公共祖先的golang实现
查看>>
【ArcGIS】文件地理数据库,个人地理数据库与ArcSDE的局别
查看>>
电子商务网站必须具备的六大功能
查看>>
洛谷-3930(我在洛谷上也写了题解)
查看>>
提交表单 - 详解
查看>>
选择排序分析
查看>>
django-xadmin的登陆权限设置
查看>>
实验二——网络嗅探与欺骗.
查看>>
mini batch
查看>>
【Android】实验5 数独游戏界面设计-报告提交时间:2016.4.15
查看>>
1.3:Render Pipeline and GPU Pipeline
查看>>
java设计模式-单例模式
查看>>
Java构造和解析Json数据的两种方法详解二
查看>>
系统句柄报too many files open
查看>>