有时,业务库直接将页面的url存储在日志表中,访问的page携带参数,此时获取参数就成为了问题,需要从字段中截取,那么hive sql如何解析url呢,来看看。
Every HTTP URL conforms to the syntax of a generic URI. A generic URI is of the form:
1 | scheme:[//[user:password@]host[:port]][/]path[?query][#fragment] |
1.从url返回PROTOCOL
1 | hive> select parse_url('https://www.baidu.com/s?cl=3&tn=baidutop10&fr=top1000&wd=大唐不夜城着火&rsv_idx=2&rsv_dl=fyb_n_homepage', 'PROTOCOL'); |
2.从url返回HOST
1 | hive> select parse_url('https://www.baidu.com/s?cl=3&tn=baidutop10&fr=top1000&wd=大唐不夜城着火&rsv_idx=2&rsv_dl=fyb_n_homepage', 'HOST'); |
3.从url返回PATH
1 | hive> select parse_url('https://www.baidu.com/s?cl=3&tn=baidutop10&fr=top1000&wd=大唐不夜城着火&rsv_idx=2&rsv_dl=fyb_n_homepage', 'PATH'); |
4.从url返回QUERY
1 | hive> select parse_url('https://www.baidu.com/s?cl=3&tn=baidutop10&fr=top1000&wd=大唐不夜城着火&rsv_idx=2&rsv_dl=fyb_n_homepage', 'QUERY'); |
5.从url返回QUERY中指定的参数的值
1 | hive> select parse_url('https://www.baidu.com/s?cl=3&tn=baidutop10&fr=top1000&wd=大唐不夜城着火&rsv_idx=2&rsv_dl=fyb_n_homepage', 'QUERY', 'wd'); |
6.从url返回FRAGMENT标识符
1 | hive> select parse_url('https://www.baidu.com/s?cl=3&tn=baidutop10&fr=top1000&wd=大唐不夜城着火&rsv_idx=2&rsv_dl=fyb_n_homepage#REGEXP_REPLACT', 'REF'); |
7.从url返回FILE
1 | //一般为 path?query |
8.从url返回AUTHORITY
1 | //userinfo@host:port |
9.从url返回USERINFO
1 | hive> select parse_url('http://tester:123456@www.baidu.com?cl=3&tn=baidutop10&fr=top1000&wd=大唐不夜城着火&rsv_idx=2&rsv_dl=fyb_n_homepage', 'USERINFO'); |
It’s never too late to learn.
书山有路勤为径,学海无涯苦作舟。
欢迎关注微信公众号:【程序员写书】
喜欢宠物的朋友可以关注:【电巴克宠物Pets】
一起学习,一起进步。
