DeveloperGuide Hive UDF
Creating Custom UDFs
First, you need to create a new class that extends UDF, with one or more methods named evaluate.
package com.example.hive.udf;import org.apache.hadoop.io.Text;public final class Lower extends UDF { public Text evaluate(final Text s) { if (s == null) { return null; } }} |
(Note that there's already a built-in function for this, it's just an easy example).
After compiling your code to a jar, you need to add this to the Hive classpath. See the section below on deploying jars.
Once Hive is started up with your jars in the classpath, the final step is to register your function as described in Create Function:
|
|
Now you can start using it:
hive> select my_lower(title), sum(freq) from titles group by my_lower(title);...Ended Job = job_200906231019_0006OKcmo 13.0vp 7.0 |
For a more involved example, see this page.
As of Hive 0.13, you can register your function as a permanent UDF either in the current database or in a specified database, as described in Permanent Functions. For example:
|
|
Deploying Jars for User Defined Functions and User Defined SerDes
In order to start using your UDF, you first need to add the code to the classpath:
hive> add jar my_jar.jar; |
By default, it will look in the current directory. You can also specify a full path:
hive> add jar /tmp/my_jar.jar; |
Your jar will then be on the classpath for all jobs initiated from that session. To see which jars have been added to the classpath you can use:
hive> list jars; |
See Hive CLI for full syntax and more examples.
As of Hive 0.13, UDFs also have the option of being able to specify required jars in the CREATE FUNCTION statement:
CREATE FUNCTION myfunc AS 'myclass' USING JAR 'hdfs:///path/to/jar'; |
This will add the jar to the classpath as if ADD JAR had been called on that jar.
DeveloperGuide Hive UDF的更多相关文章
- Hive UDF初探
1. 引言 在前一篇中,解决了Hive表中复杂数据结构平铺化以导入Kylin的问题,但是平铺之后计算广告日志的曝光PV是翻倍的,因为一个用户对应于多个标签.所以,为了计算曝光PV,我们得另外创建视图. ...
- Hive UDF 实验1
项目中使用的hive版本低于0.11,无法使用hive在0.11中新加的开窗分析函数. 在项目中需要使用到row_number()函数的地方,有人写了udf来实现这个功能. new java proj ...
- hive UDF添加方式
hive UDF添加的方式 1.添加临时函数,只能在此会话中生效,退出hive自动失效 hive> add jar /home/jtdata/hiveUDF/out0.jar; Added [/ ...
- [转]HIVE UDF/UDAF/UDTF的Map Reduce代码框架模板
FROM : http://hugh-wangp.iteye.com/blog/1472371 自己写代码时候的利用到的模板 UDF步骤: 1.必须继承org.apache.hadoop.hive ...
- 2、Hive UDF编程实例
Hive的UDF包括3种:UDF(User-Defined Function).UDAF(User-Defined Aggregate Function)和UDTF(User-Defined Tabl ...
- Hive UDF 用户自定义函数 编程及使用
首先创建工程编写UDF 代码,示例如下: 1. 新建Maven项目 udf 本机Hadoop版本为2.7.7, Hive版本为1.2.2,所以选择对应版本的jar ,其它版本也不影响编译. 2. po ...
- Hive UDF开发-简介
Hive进行UDF开发十分简单,此处所说UDF为Temporary的function,所以需要hive版本在0.4.0以上才可以. Hive的UDF开发只需要重构UDF类的evaluate函数即可.例 ...
- 【转】HIVE UDF UDAF UDTF 区别 使用
原博文出自于:http://blog.csdn.net/longzilong216/article/details/23921235(暂时) 感谢! 自己写代码时候的利用到的模板 UDF步骤: 1 ...
- HIVE udf实例
本例中udf来自<hive编程指南>其中13章自定义函数中一个例子. 按照步骤,第一步,建立一个项目,创建 GenericUDFNvl 类. /** * 不能接受第一个参数为null的情况 ...
随机推荐
- 什么样的IT业务适合外包?
很多公司都应该遇到过这样的问题,什么样的IT业务才适合外包呢? 百度大家都可以百度的到一些信息,比如: 针对这样的推荐答案,是否也需要认真思考一下,我需要外包的业务是什么样的业务?是不是真的适合外包? ...
- Linux~其实shell脚本也很简单
用了两个的centos之后,也想看看它的脚本,我们知道shell这个东西就像windows里的批处理,它可以将一些语句进行组合,然后统一去执行,感觉挺方便的. shell文件的组成 shell语言环境 ...
- 【算法与数据结构专场】BitMap算法基本操作代码实现
上篇我们讲了BitMap是如何对数据进行存储的,没看过的可以看一下[算法与数据结构专场]BitMap算法介绍 这篇我们来讲一下BitMap这个数据结构的代码实现. 回顾下数据的存储原理 一个二进制位对 ...
- 【ASP.NET Core快速入门】(十五)MVC开发:ReturnUrl实现、Model后端验证 、Model前端验证
ReturnUrl实现 我们要实现returnUrl,我们需要在注册(Register)方法中接收传进的returnUrl并给它默认值null,然后将它保存在ViewData里面 然后我们定义一个内部 ...
- RabbitMQ消息队列(十二)-性能测试
硬件配置 宿主机用的联想3850X6的服务器四颗E7-4850v3的处理器,DDR4内存,两块1.25TB的pcie固态.在宿主机上使用的事esxi5.5的虚拟化平台,在子系统中安装RabbitMQ和 ...
- 补习系列(6)- springboot 整合 shiro 一指禅
目标 了解ApacheShiro是什么,能做什么: 通过QuickStart 代码领会 Shiro的关键概念: 能基于SpringBoot 整合Shiro 实现URL安全访问: 掌握基于注解的方法,以 ...
- [ SSH框架 ] Spring框架学习之三(AOP开发和注解的使用)
一.Spring 使用 AspectJ 进行 AOP 的开发:注解的方式 1.1 引入相关的jar包 1.2 引入spring的配置文件 <?xml version="1.0" ...
- Spring Boot 2.x(十四):整合Redis,看这一篇就够了
目录 Redis简介 Redis的部署 在Spring Boot中的使用 Redis缓存实战 寻找组织 程序员经典必备枕头书免费送 Redis简介 Redis 是一个开源的使用 ANSI C 语言编写 ...
- web缓存策略之HTTP缓存大全
一. web缓存总分类 数据库数据缓存 Web应用,特别是SNS类型的应用,往往关系比较复杂,数据库表繁多,如果频繁进行数据库查询,很容易导致数据库不堪重荷.为了提供查询的性能,会将查询后的数据放到内 ...
- 【Angular专题】 (3)装饰器decorator,一块语法糖
目录 一. Decorator装饰器 二. Typescript中的装饰器 2.1 类装饰器 2.2 方法装饰器 2.3 访问器装饰器 2.4 属性装饰器 2.5 参数装饰器 三. 用ES5代码模拟装 ...