hive拼接两个字段,一个字段值作为K,另一个字段值作为V,id不唯一,将多行组成json串
select
id,
concat('{', regexp_replace(cast(sort_array(collect_set(kv)) as string),'(\"\":\"0\"\,)|\\[|\\]','') ,'}') kv
from
(
select
id,
concat(concat('\"',k,'\"'),':',concat('\"',v,'\"')) kv
from tablename
)group by id