`

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 函数的编写方法,包括创建 UDF 类、实现自定义函数逻辑、编译和打包 UDF jar 包、上传至 Hive 服务器并注册自定义函数。 一、创建 UDF 类 为了实现自定义 UDF 函数,需要创建一...

    HIVE自定义UDF函数

    而自定义用户定义函数(UDF)是 Hive 中的一个重要功能,允许用户根据自己的需求编写自定义函数,以便在 Hive 查询中使用。 如何在 Hive 中创建自定义 UDF 函数: 步骤一:编写 Java 程序 首先,您需要编写一个 ...

    hive自定义udf函数实战

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

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

    为了满足特定的业务需求,Hive提供了用户定义函数(UDF)的功能,允许用户自定义处理数据的逻辑。在这个“hive-udf”项目中,我们主要探讨的是如何利用Java编写UDF来实现两个地址间的距离计算以及省市区位置的解析。...

    Hive的Udf函数进行数据脱敏

    总结来说,通过自定义UDF,我们可以方便地在Hive中实现数据脱敏功能,以保护敏感信息。这个过程涉及到Java编程、Hive API的使用以及SQL查询的编写。在实际应用中,可能需要根据业务需求调整UDF的行为,例如改变保留...

    Spark不能使用hive自定义函数.doc

    ### Spark与Hive自定义函数兼容性问题解析 在大数据处理领域,Apache Spark 和 Apache Hive 都是非常重要的工具。Spark 是一种快速通用的大规模数据处理系统,而Hive 则是一种数据仓库工具,主要用于对存储在 ...

    hive UDF需要jar包

    在Hive中,UDF(User Defined Functions)是用户自定义函数,允许开发人员扩展Hive的内置功能,以满足特定的数据处理需求。Hive UDF的实现通常涉及到编写Java代码,并将其打包成JAR(Java Archive)文件,然后在Hive...

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

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

    hive的UDF的编写.docx

    在hive中,UDF是用户自定义的函数,可以根据业务需求编写自定义的函数来实现特定的数据处理逻辑。UDF可以将复杂的数据处理逻辑封装在一个函数中,以便于在hive查询中使用。 使用Java编写hive的UDF 使用Java编写...

    hive的自定义函数

    1. **复制到源码目录**:将自定义UDF的Java文件复制到`{Hive_source}\ql\src\java\org\apache\hadoop\hive\ql\udf`目录。 2. **修改注册文件**:在`FunctionRegistry.java`文件中导入自定义UDF类,并使用`...

    Hive_UDF.rar_hive_sqoop

    在这个名为“Hive_UDF.rar_hive_sqoop”的压缩包中,我们可能会找到关于如何集成和自定义 Hive 用户定义函数(UDF)以及利用 Sqoop 进行数据导入导出的详细资料。 首先,让我们深入理解 Hive UDF。Hive 支持多种...

    hive自定义函数demo

    本示例“hive自定义函数demo”将探讨如何在Hive中开发和使用自定义函数(UDF),这对于扩展Hive的功能和适应特定业务需求至关重要。下面,我们将深入学习与Hive自定义函数相关的知识。 1. **什么是Hive UDF?** ...

    hive数仓、hive SQL 、 hive自定义函数 、hive参数深入浅出

    3. Hive自定义函数(UDF): - UDF定义:用户可以编写Java代码实现特定功能的函数,然后在Hive SQL中调用。 - UDAF(用户定义的聚合函数):用于处理一组输入值并返回单个值,如自定义平均值、众数等。 - UDTF...

    HIve UDF 说明书

    在Hive UDF的使用说明书中,包含了关于Hive的内置操作符、内置函数、聚合函数、表生成函数、以及自定义UDF的创建等内容。这些内容是学习和使用Hive UDF不可或缺的知识点。 内置操作符部分涵盖了数学函数和操作符、...

    dataiku hive udf

    Hive UDF(User Defined Functions)则是Hive中扩展其功能的关键部分,允许用户自定义函数来处理特定的数据分析任务。"dataiku hive udf"项目提供的是一套通用的Hive UDF源码,对于那些想深入开发Hadoop Hive应用的...

    hive-udf:hive自定义函数

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

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

    然而,有时Hive的内置函数并不能满足所有的业务需求,这时我们就需要创建自定义函数(UDF,User Defined Function)。这篇博文主要探讨了如何在Hive中创建自定义函数以及如何加载它们,这对于深化Hive的使用和解决...

    Hive UDF开发

    Hive UDF是指用户可以根据自己的业务需求,自定义Java类来实现特定的数据处理逻辑,并将其封装成函数的形式供Hive SQL使用。根据功能不同,Hive UDF主要分为三类:基本UDF、通用UDF (GenericUDF) 和表生成UDF (UDTF)...

    各种情况手机号清洗udf函数(hive impala)

    - 步骤2:调用自定义UDF,使用正则表达式进行格式规范化。 - 步骤3:检查清洗后的手机号码,确保其符合预期的格式。 - 步骤4:如果需要,可进一步进行缺失值处理或异常值检测。 7. **实践应用**:手机号码清洗在...

    base64加密解密的hive udf函数

    在Hive中,我们可以编写Java代码来创建自定义UDF。以下是一个简单的Base64加密和解密UDF示例: 1. 创建一个Java项目,引入Hive相关的依赖库,如`hive-exec`和`hive-serde`。 2. 编写一个名为`Base64UDF`的类,继承...

Global site tag (gtag.js) - Google Analytics