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的情况 ...
随机推荐
- asp.net core系列 34 EF保存数据(1)
一. 基本数据 每个EF上下文实例都有一个 ChangeTracker(更改跟踪器),它负责跟踪需要写入数据库的更改. 当更改实体类的实例时(修改属性,删除实例,新建实例等),这些更改会记录在 Cha ...
- 在 Vue 结合 Axios 使用过程 中 post 方法,后台无法接受到数据问题
关于在 vue 中 使用 axios 相关 bug 首先,我们来看下 axios 的 github 传送门 axios 然后我们再介绍下 axios 的作者的 github 传送门 Matt 最后,我 ...
- IntelliJ IDEA部署tomcat时Edit Configuration Deployment无artifact选项
IntelliJ IDEA,IntelliJ Idea创建web项目之后在配置web项目时,选择Edit Configration部署Tomcat,Deployment里点击添加无artifact选项 ...
- ReentrantLock原理学习
上文我们学习了ReentrantLock的基本用法,在最后我们留下了一个问题,ReentrantLock获取的锁是什么锁呢?本文我们就从源码的角度来一探究竟.本文涉及到的源码对应JDK版本为1.8. ...
- synchronized底层实现学习
上文我们总结了 synchronized 关键字的基本用法以及作用,并未涉及 synchronized 底层是如何实现的,所谓刨根问底,本文我们就开始 synchronized 原理的探索之旅吧(*& ...
- web进修之—Hibernate 关系映射(3)
概述 Hibernate的关系映射是Hibernate使用的难点或者是重点(别担心,不考试哦~),按照不同的分类方式可以对这些映射关系做一个分类,如: 按对象对应关系分: 一对一 多对一/一对多 多对 ...
- scrapy爬虫学习系列五:图片的抓取和下载
系列文章列表: scrapy爬虫学习系列一:scrapy爬虫环境的准备: http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_python_00 ...
- RSA签名的PSS模式
本文由云+社区发表 作者:mariolu 一.什么是PSS模式? 1.1.两种签名方式之一RSA-PSS PSS (Probabilistic Signature Scheme)私钥签名流程的一种填充 ...
- windows7安装MySQL-python遇到的坑
最近在windows环境上搭建flask使用环境,遇到过很多坑,这次就记录下安装flask-mysqldb所遇到的坑. 正常逻辑是使用pip install flask-mysqldb进行安装.但是会 ...
- webpack4.0各个击破(4)—— Javascript & splitChunk
目录 一. Js模块化开发 二. Js文件的一般打包需求 三. 使用webpack处理js文件 3.1 使用babel转换ES6+语法 3.2 脚本合并 3.3 公共模块识别 3.4 代码分割 3.5 ...