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的情况 ...
随机推荐
- JavaScript 中 正则替换 replace
本文初步介绍 replace 在 js 中,我们常常会遇到 用来 解决开发中常会遇到的 问题的 知识总结, 如果你已经 非常熟悉,又可以绕道了. 定义和用法 replace() 方法用于在字符串中常用 ...
- ubuntu16.04 Golang语言开发环境搭建
golang即go语言是跨平台的语言,适用于windows 和linux平台,下面介绍linux平台下ubuntu16.04系统下的开发环境搭建过程. 一.安装开发必备环境 执行下面命令分别安装git ...
- Java开发知识之Java入门
Java开发知识之Java入门 一丶了解JAVA的版本 JAVA 有三个版本 JAVA SE: 标准版,开发桌面跟商务应用程序 JAVA SE 包括了Java的核心类库,集合,IO 数据库连接 以及网 ...
- 痞子衡嵌入式:并行接口NAND互操作性标准(JEDEC-JESD230)
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是JESD230标准. 众所周知,最早也最流行的Raw NAND接口标准是ONFI标准,痞子衡在 并行接口NAND标准(ONFI)及SLC ...
- Flask的请求处理机制
在Flask的官方文档中是这样介绍Flask的: 对于Web应用,与客户端发送给服务器的数据交互至关重要.在Flask中由全局的request对象来提供这些信息 属性介绍 request.method ...
- Haskell复习笔记(二)
Haskell中的递归 递归就是定义函数以调用自身的方式,关于递归解决问题的实例有很多,如斐波那契数列,还有汉诺塔问题,递归也正是Haskell中用来解决循环问题的关键. 自定义maxinum函数 m ...
- 使用NOPI写入Excel基础代码
using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.IO; using Sy ...
- .net 上传文件 Failed to load resource: net::ERR_CONNECTION_RESET Bug 解决
环境: .net 4.0 ashx一般处理程序 使用 html5 FormData ajax上传文件 功能如下:如果用户有登录,则对文件进行处理:如果用户没登录,则直接返回json,提示用户未登录 遇 ...
- 微信小程序支付接入注意点
一.微信支付后台服务器部署 服务器采用ubuntu16.04 + php7.0 + apache2.0. 微信支付后台服务使用了curl 和 samplexml ,因此php.ini配置中必须开启这两 ...
- OO第一单元作业总结
oo第一单元的作业是对多项式的求导.下面就是对三次作业分别进行分析. 第一次作业 分析 第一次作业相对来讲比较简单,甚至不用面向对象的思想都能十分轻松的完成(实际上自己就没有使用),包含的内容只有常数 ...