HIVE函数

1、日期函数返回值类型 名称 描述 string from_unixtime(int unixtime) 将时间戳(unix epoch秒数)转换为日期时间字符串,例如from_unixtime(0)="1970-01-01 00:00:00" bigint unix_tim
摘要由CSDN通过智能技术生成

1、日期函数

返回值类型

名称

描述

string

from_unixtime(int unixtime)

将时间戳(unix epoch秒数)转换为日期时间字符串,例如from_unixtime(0)="1970-01-01 00:00:00"

bigint

unix_timestamp()

获得当前时间戳

bigint

unix_timestamp(string date)

获得date表示的时间戳

bigint

to_date(string timestamp)

返回日期字符串,例如to_date("1970-01-01 00:00:00") = "1970-01-01"

string

year(string date)

返回年,例如year("1970-01-01 00:00:00") = 1970,year("1970-01-01") = 1970

int

month(string date)

 

int

day(string date) dayofmonth(date)

 

int

hour(string date)

 

int

minute(string date)

 

int

second(string date)

 

int

weekofyear(string date)

 

int

datediff(string enddate, string startdate)

返回enddate和startdate的天数的差,例如datediff('2009-03-01', '2009-02-27') = 2

int

date_add(string startdate, int days)

加days天数到startdate: date_add('2008-12-31', 1) = '2009-01-01'

int

date_sub(string startdate, int days)

减days天数到startdate: date_sub('2008-12-31', 1) = '2008-12-30'

2、条件函数

返回值类型

名称

描述

-

if(boolean testCondition, T valueTrue, T valueFalseOrNull)

当testCondition为真时返回valueTrue,testCondition为假或NULL时返回valueFalseOrNull

-

COALESCE(T v1, T v2, ...)

返回列表中的第一个非空元素,如果列表元素都为空则返回NULL

-

CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END

a = b,返回c;a = d,返回e;否则返回f

-

CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END

a 为真,返回b;c为真,返回d;否则e

3、字符串函数

返回值类型

名称 

描述

Int

length(string A)

返回字符串长度

String

reverse(string A)

反转字符串

String

concat(string A, string B...)

合并字符串,例如concat('foo', 'bar')='foobar'。注意这一函数可以接受任意个数的参数

String

substr(string A, int start) substring(string A, int start)

返回子串,例如substr('foobar', 4)='bar'

String

substr(string A, int start, int len) substring(string A, int start, int len)

返回限定长度的子串,例如substr('foobar', 4, 1)='b'

String

upper(string A) ucase(string A)

转换为大写

String

lower(string A) lcase(string A)

转换为小写

String

trim(string A)

 

String

ltrim(string A)

 

String

rtrim(string A)

 

String

regexp_replace(string A, string B, string C)

Returns the string resulting from replacing all substrings in B that match the Java regular expression syntax(See Java regular expressions syntax) with C e.g. regexp_replace("foobar", "oo|ar", "") returns 'fb.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\\s' is necessary to match whitespace, etc.

String

regexp_extract(string subject, string pattern, int intex)

返回使用正则表达式提取的子字串。例如,regexp_extract('foothebar', 'foo(.*?)(bar)', 2)='bar'。注意使用特殊字符的规则:使用'\s'代表的是字符's';空白字符需要使用'\\s',以此类推。

String

parse_url(string urlString, string partToExtract)

解析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&field=2','QUERY','query')='1'可以用来取出外部渲染参数key对应的value值

parse_url('http://facebook.com/path/p1.php?query=1&field=2','QUERY','field')='2'

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'

String

get_json_object(string json_string, string path)

解析json字符串。若源json字符串非法则返回NULL。path参数支持JSONPath的一个子集,包括以下标记:

$: Root object

[]: Subscript operator for array

&: Wildcard for []

.: Child operator

String

space(int n)

返回一个包含n个空格的字符串

String

repeat(string str, int n)

重复str字符串n遍

String

ascii(string str)

返回str中第一个字符的ascii码

String

lpad(string str, int len, string pad)

左端补齐str到长度为len。补齐的字符串由pad指定。

String

rpad(string str, int len, string pad)

右端补齐str到长度为len。补齐的字符串由pad指定。

Array

split(string str, string pat)

返回使用pat作为正则表达式分割str字符串的列表。例如,split('foobar', 'o')[2] = 'bar'。?不是很明白这个结果

Int

find_in_set(string str, string strList)

Returns the first occurance of str in strList where strList is a comma-delimited string. Returns null if either argument is null. Returns 0 if the first argument contains any commas. e.g. find_in_set('ab', 'abc,b,ab,c,def') returns 3

返回值类型

名称 

描述

Int

length(string A)

返回字符串长度

String

reverse(string A)

反转字符串

String

concat(string A, string B...)

合并字符串,例如concat('foo', 'bar')='foobar'。注意这一函数可以接受任意个数的参数

String

substr(string A, int start) substring(string A, int start)

返回子串,例如substr('foobar', 4)='bar'

String

substr(string A, int start, int len) substring(string A, int start, int len)

返回限定长度的子串,例如substr('foobar', 4, 1)='b'

String

upper(string A) ucase(string A)

转换为大写

String

lower(string A) lcase(string A)

转换为小写

String

trim(string A)

 

String

ltrim(string A)

 

String

rtrim(string A)

 

String

regexp_replace(string A, string B, string C)

Returns the string resulting from replacing all substrings in B that match the Java regular expression syntax(See Java regular expressions syntax) with C e.g. regexp_replace("foobar", "oo|ar", "") returns 'fb.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\\s' is necessary to match whitespace, etc.

String

regexp_extract(string subject, string pattern, int intex)

返回使用正则表达式提取的子字串。例如,regexp_extract('foothebar', 'foo(.*?)(bar)', 2)='bar'。注意使用特殊字符的规则:使用'\s'代表的是字符's';空白字符需要使用'\\s',以此类推。

String

parse_url(string urlString, string partToExtract)

解析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&field=2','QUERY','query')='1'可以用来取出外部渲染参数key对应的value值

parse_url('http://facebook.com/path/p1.php?query=1&field=2','QUERY','field')='2'

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'

String

get_json_object(string json_string, string path)

解析json字符串。若源json字符串非法则返回NULL。path参数支持JSONPath的一个子集,包括以下标记:

$: Root object

[]: Subscript operator for array

&: Wildcard for []

.: Child operator

String

space(int n)

返回一个包含n个空格的字符串

String

repeat(string str, int n)

重复str字符串n遍

String

ascii(string str)

返回str中第一个字符的ascii码

String

lpad(string str, int len, string pad)

左端补齐str到长度为len。补齐的字符串由pad指定。

String

rpad(string str, int len, string pad)

右端补齐str到长度为len。补齐的字符串由pad指

Array

split(string str, string pat)

返回使用pat作为正则表达式分割str字符串的列表。例如,split('foobar', 'o')[2] = 'bar'。?不是很明白这个结果

Int

find_in_set(string str, string strList)

Returns the first occurance of str in strList where strList is a comma-delimited string. Returns null if either argument is null. Returns 0 if the first argument contains any commas. e.g. find_in_set('ab', 'abc,b,ab,c,def') returns 3



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值