Welcome to aparke’s blog!
HIVE的内置函数
时间处理函数:
取当前时间的毫秒时间戳
select unix_timestamp();
_c0
1552360005unix时间戳转字符串
from_unixtime(bigint unixtime[,string format])
示例:
select from_unixtime(unix_timestamp());
_c0
2019-03-12 11:10:00
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss');
_c0
2019-03-12 11:10:16字符串转时间戳
unix_timestamp(string date,string pattern)
示例:
select unix_timestamp("2019-03-12 11:10:16");
_c0
1552360216
select unix_timestamp("2019/03/12 11:10:16","yyyy/MM/dd HH:mm:ss");
_c0
1552360216将字符串转成date类型
select to_date("2019-03-12 11:21:22");
_c0
2019-03-12时间类型转换函数:
select from_unixtime(cast('21938792183' as bigint),'yyyy-MM-dd HH:mm:ss')
_c0
2665-03-19 12:56:23
select cast("8" as int);-->8
select cast("2019-03-10" as date); --> 2019-03-10
select current_timestamp;--时间戳
select current_timestamp;--hive中的,mysql没有
_c0
2019-03-10 21:26:49.755
select cast (current_timestamp() as date);
_c0
2019-03-10
select unix_timestamp();--毫秒表示
1552224511
select cast(unix_timestamp() as date);,不支持转成date类
字符串处理函数
字符串拼接
concat_ws('.','192','168','33','66') _c0
192.168.33.66字符串切割
select split('18:male:beijing',':');
_c0
["18","male","beijing"]
切完后为一个数组并找出找出他的性别
select split('18:male:beijing',':')[1];
_c0
male字符串截取
substr内置函数元素默认从1开始
select substr("abcd",1,3);
select substr("abcd",0,3);
substr("abcd",1,3) --> 'abc'字符串拼接
select concat('abc','def') --> 'abcdef'
select substr(url,1,21) from groupby.access_time;
+------------------------+--+
| _c0 |
+------------------------+--+
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
| http://www.aparke.cn/ |
+------------------------+--+
Json数据解析函数
get_json_object('{\"key1\":3333,\"key2\":4444}' , '$.key1') --> 3333 |
url解析函数
parse_url_tuple('http://www.edu360.cn/bigdata/baoming?userid=8888','HOST','PATH','QUERY','QUERY:userid') |