查看函数
show functions;
desc functions 函数名
parse_url
parse_url(url,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' <pre class="sql" name="code">
hive> select parse_url(‘http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1′, ‘QUERY’, ‘k1′) from dual;
v1
时间函数
获取当前日期 unix_timestamp()
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') from t1;
获取第几周
weekofyear()
获取星期几可以使用以下函数
pmod(datediff('dateTimeExp', '2012年任意一个星期天的日期'), 7)
字符串函数
正则表达式替换函数 regexp_replace
语法: regexp_replace(string A,string B,string C)
返回值: string
说明: 将字符串A中的符合java正则表达式B的部分替换成C.注意,有些情况写要使用转意字符
举例:
hive> select regexp_replace('foobar','oo|ar','') from t1;
fb
正则表达式解析函数; regexp_extract
语法: regexp_extract(string subjext,string pattern,int index)
返回值: string
说明: 将字符串subject按照parttern正则表达式的规则拆分,返回index指定的字符。注意,在有些情况下要转义字符
举例:
hive> select regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 1) from dual;
the
hive> select regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 2) from dual;
bar
hive> select regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 0) from dual;
foothebar
json解析函数:get_json_object
语法: get_json_object(string json_string, string path)
返回值: string
说明:解析json的字符串json_string,返回path指定的内容。如果输入的json字符串无效,那么返回NULL。