`

hive 自定义udf

    博客分类:
  • hive
阅读更多
Hive的预定义UDF函数列表如下

abs(x) - returns the absolute value of x
acos(x) - returns the arc cosine of x if -1<=x<=1 or NULL otherwise
ascii(str) - returns the numeric value of the first character of str
asin(x) - returns the arc sine of x if -1<=x<=1 or NULL otherwise
bin(n) - returns n in binary
                        转换成二进制数

ceil(x) - Find the smallest integer not smaller than x
ceiling(x) - Find the smallest integer not smaller than x
coalesce(a1, a2, ...) - Returns the first non-null argument
                        返回第一个非空的参数

concat(str1, str2) - returns the concatenation of str1 and str2
conv(num, from_base, to_base) - convert num from from_base to to_base
                         转换进制,从from_base进制转换成to_base

cos(x) - returns the cosine of x (x is in radians)
date_add(start_date, num_days) - Returns the date that is num_days after start_date.
                         按天做日期加,日期的格式为'yyyy-MM-dd HH:mm:ss'或'yyyy-MM-dd',下同

date_sub(start_date, num_days) - Returns the date that is num_days before start_date.
                        按天做日期减

datediff(date1, date2) - Returns the number of days between date1 and date2
                         按天做日期差

day(date) - Returns the date of the month of date
                         同dayofmonth

dayofmonth(date) - Returns the date of the month of date
elt(n, str1, str2, ...) - returns the n-th string
exp(x) - Returns e to the power of x
floor(x) - Find the largest integer not greater than x
from_unixtime(unix_time, format) - returns unix_time in the specified format
get_json_object(json_txt, path) - Extract a json object from path
解析json object。

path支持JSONPath的一个子集,包括:

  * $ : Root object

  *  . : Child operator

  * [] : Subscript operator for array

  * * : Wildcard for []

例如,src_json 表只包含一列json,其中的一行内容为:

+-------------------------------------------------------------------+
                                json
+-------------------------------------------------------------------+
{"store":
   {"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],
    "bicycle":{"price":19.95,"color":"red"}
   },
  "email":"amy@only_for_json_udf_test.net",
  "owner":"amy"
}
+-------------------------------------------------------------------+
json内容可以用以下查询语句解析

hive> SELECT get_json_object(src_json.json, '$.owner') FROM src_json;
amy
hive> SELECT get_json_object(src_json.json, '$.store.fruit[0]') FROM src_json;
{"weight":8,"type":"apple"}
hive> SELECT get_json_object(src_json.json, '$.non_exist_key') FROM src_json;
NULL
hash(a1, a2, ...) - Returns a hash value of the arguments
hex(n or str) - Convert the argument to hexadecimal
index(a, n) - Returns the n-th element of a
instr(str, substr) - Returns the index of the first occurance of substr in str
isnotnull a - Returns true if a is not NULL and false otherwise
isnull a - Returns true if a is NULL and false otherwise
lcase(str) - Returns str with all characters changed to lowercase
length(str) - Returns the length of str
ln(x) - Returns the natural logarithm of x
locate(substr, str[, pos]) - Returns the position of the first occurance of substr in str after position pos
log([b], x) - Returns the logarithm of x with base b
log10(x) - Returns the logarithm of x with base 10
log2(x) - Returns the logarithm of x with base 2
lower(str) - Returns str with all characters changed to lowercase
lpad(str, len, pad) - Returns str, left-padded with pad to a length of len
ltrim(str) - Removes the leading space characters from str
month(date) - Returns the month of date
negative a - Returns -a
parse_url(url, partToExtract[, key]) - extracts a part from a URL
解析URL字符串,partToExtract的选项包含[HOST,PATH,QUERY,REF,PROTOCOL,FILE,AUTHORITY,USERINFO]。

例如, * parse_url('http://facebook.com/path/p1.php?query=1', 'HOST')返回'facebook.com' * parse_url('http://facebook.com/path/p1.php?query=1', 'PATH')返回'/path/p1.php' * parse_url('http://facebook.com/path/p1.php?query=1', 'QUERY')返回'query=1',可以指定key来返回特定参数,key的格式是QUERY:<KEY_NAME>,例如QUERY:k1 * parse_url('http://facebook.com/path/p1.php?query=1#Ref', 'REF')返回'Ref' * parse_url('http://facebook.com/path/p1.php?query=1#Ref', 'PROTOCOL')返回'http'

a pmod b - Compute the positive modulo
positive a - Returns a
pow(x1, x2) - raise x1 to the power of x2
power(x1, x2) - raise x1 to the power of x2
rand([seed]) - Returns a pseudorandom number between 0 and 1
regexp_extract(str, regexp[, idx]) - extracts a group that matches regexp:例如regexp_extract(url,'.*pvid=(.*?)(&|#|$)',1)!=""其中()的位置即为后面参数1,2,3所获得的数值,当前例子为第一个括号匹配的值
regexp_replace(str, regexp, rep) - replace all substrings of str that match regexp with rep
repeat(str, n) - repeat str n times
reverse(str) - reverse str
round(x[, d]) - round x to d decimal places
rpad(str, len, pad) - Returns str, right-padded with pad to a length of len
rtrim(str) - Removes the trailing space characters from str
sin(x) - returns the sine of x (x is in radians)
size(a) - Returns the size of a
space(n) - returns n spaces
split(str, regex) - Splits str around occurances that match regex ,例如split(split(f.field_ext1, ",")[2],"_")[0],
sqrt(x) - returns the square root of x
substr(str, pos[, len]) - returns the substring of str that starts at pos and is of length len
substring(str, pos[, len]) - returns the substring of str that starts at pos and is of length len
to_date(expr) - Extracts the date part of the date or datetime expression expr
                         返回date部分的字符串('yyyy-MM-dd')。expr可以是date或datetime('yyyy-MM-dd HH:mm:ss')。

trim(str) - Removes the leading and trailing space characters from str
ucase(str) - Returns str with all characters changed to uppercase
unix_timestamp([date[, pattern]]) - Returns the UNIX timestamp
返回unix风格的time epoch(1970-01-01 00:00:00以来的秒数)。默认返回当前时间的time epoch。

制定date时,返回指定时间的time epoch。可以用pattern制定格式化字符串,用于格式化date。例如 unix_timestamp('20121228', 'yyyyMMdd')返回1356624000

upper(str) - Returns str with all characters changed to uppercase
year(date) - Returns the year of date
0
4
分享到:
评论

相关推荐

    hive自定义UDF编写函数.docx

    hive的udf函数实现

    hive自定义udf函数实战

    udf函数,用户自定义函数,可以直接在sql语句中计算的函数 优点: 允许实现模块化的程序设计、方便修改代码、增加函数 UDF的执行速度很快,通过缓存计划在语句重复执行时降低代码的编译开销,比存储方法的执行效率...

    hive-udf(两地址间距离计算+省市区位置解析(Java代码))

    地址转换成经纬度+两地址间距离计算+省市区位置解析(Java代码) Hive自定义函数的封装

    Hive的Udf函数进行数据脱敏

    udf开发–做个简单脱敏udf保留前5位,后面全部替换成*****

    hive的自定义函数

    简单介绍了hive自定义函数的编写步骤以及使用。

    * hive脱敏UDF函数 *对一些敏感信息进行脱敏处理,替换位置可自定义,脱敏符号可随机也可自定义

    * 脱敏UDF函数 * 功能:对一些敏感信息进行脱敏处理,替换方式可选择自定义替换,如'#','*'等,,如不指定脱敏符号,使用个随机字符替换 * 脱敏位置可自定义,不指定位置,会对数据进行全脱敏 * 例如身份证信息: ...

    hive-udf:hive自定义函数

    hive-udfhive自定义函数主要实现hive3种自定义函数1,udf函数,主要用于处理一对一数据处理2,udtf函数,主要用于处理一对多数据处理2,udaf函数,主要用与处理多对一数据聚合处理

    Hive UDF开发

    详细介绍如何开发hive自定义永久函数,配套有测试数据

    Hive自定义函数

    Hive自定义函数 一. UDF(user defined function) 背景 系统内置函数无法解决所有的实际业务问题,需要开发者自己编写函数实现自身的业务实现诉求。 应用场景非常多,面临的业务不同导致个性化实现很多,故udf...

    hive 创建自定义函数 和 hive加载说明

    NULL 博文链接:https://chengjianxiaoxue.iteye.com/blog/2235666

    hive 分组取TopN

    hive不直接支持分组取TopN的操作,需要自定义udf函数打成jar包添加到hive运行环境中

    自定义hive函数

    自定义 hive udf udaf 有url解析,获取网站主域名,根据ip获取区域码,有rownum,列聚合以及一些业务实现udf。

    HelloUDF.zip

    Hive 自定义函数UDF开发手把手教程—— 创建临时函数和永久函数代码,具体创建过程参考https://blog.csdn.net/helloxiaozhe/article/details/102498567

    【63课时完整版】大数据实践HIVE详解及实战

    22.Hive中使用自定义UDF实现日期格式转换 23. HiveServer2的介绍及三种连接方式 24.Hive元数据、fetch task和严格模式的介绍 第3章:Sqoop Sqoop及用户行为分析案例 25.CDH版本框架的介绍 26. CDH版本框架的环境...

    快速学习-Hive函数

    第 7 章 函数 7.1 系统内置函数 1)查看系统自带的函数 ...2)当 Hive 提供的内置函数无法满足你的业务处理需要时,此时就可以考虑使用用户自定义函数(UDF:user-defined function)。 3)根据用户自定义函数

    hive编程指南中文版

    · 获得创建用户自定义函数(UDF)的最佳方法。 · 了解应该使用的Hive模式以及应该避免的反模式。 · 将Hive和其他数据处理程序进行整合。 · 对于NoSQL数据库和其他数据存储使用存储控制器。 · 学习在亚马逊弹性...

    Hive编程指南

    · 获得创建用户自定义函数(UDF)的最佳方法。 · 了解应该使用的Hive模式以及应该避免的反模式。 · 将Hive和其他数据处理程序进行整合。 · 对于NoSQL数据库和其他数据存储使用存储控制器。 · 学习在亚马逊弹性...

    大数据运维技术第6章 Hive组件安装配置课件.pptx

    同时,Hive也允许熟悉MapReduce开发者们开发自定义的Mappers和Reducers来处理内建的Mappers和Reducers无法完成的复杂的分析工作。Hive还允许用户编写自己定义的函数UDF,用来在查询中使用。;;;6.2 Hive组件架构;6.2 ...

    hive入门级详解

    hive入门级详解,包括数仓与传统数据库的比对,hive的存储结构与存储原理,分区分桶、hql如何转换成mapreduce、UDF自定义函数等

    大数据视频_Hive视频教程(上)

    在本课程中,你将学习到,Hive架构原理、安装配置、hiveserver2、数据类型、数据定义、数据操作、查询、自定义UDF函数、窗口函数、压缩和存储、企业级调优、以及结合谷粒影音项目需求,把整个Hive的核心知识点贯穿...

Global site tag (gtag.js) - Google Analytics