赞
踩
- select str_to_map('aaa:11&bbb:22', '&', ':');
- select str_to_map('aaa:11&bbb:22', '&', ':')['aaa'];
-
- select str_to_map('device_ds:2&uid_cnt:1','&',',') --键值分割不到,值会出现Null
综合使用示范:- select a1.appkey,a1.appsource,index_key,index_value
- from tab_sum a1
- lateral view explode(str_to_map(concat('device_ds:',a1.device_ds_cnt,'&','uid_cnt:',a1.uid_cnt),'&',':')) mid_list_tab as index_key,index_value;
2、字符串转为array- select split('aaa:11:bbb:22',':');
- ["aaa","11","bbb","22"]
- select split('aaa:11:bbb:22',':')[0];
- aaa
3、字符字段去重汇总转成array- drop table if exists xxxxx_tabletest;
- CREATE TABLE xxxxx_tabletest(
- id string,
- name string)
- ROW FORMAT SERDE
- 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
- WITH SERDEPROPERTIES (
- 'field.delim'=',',
- 'line.delim'='\n',
- 'serialization.format'=',');
- insert into xxxxx_tabletest(id,name)
- values
- ('1','A'),
- ('1','C'),
- ('1','B'),
- ('2','B'),
- ('2','C'),
- ('2','D'),
- ('3','B'),
- ('3','C'),
- ('3','D');
- select id,collect_set(name) from xxxxx_tabletest group by id;
- OK
- 1 ["A","C","B"]
- 2 ["B","C","D"]
- 3 ["B","C","D"]
- Time taken: 36.966 seconds, Fetched: 3 row(s)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。