The following query works:
with sartab as (
select 1 id, split(concat_ws(',',map_keys(map('a',0.1,'b',0.2,'c',0.15)),
array('id_queue', 'queue_disposition')),',') sar_keys,
split(concat_ws(',',map_values(map('a','0.1','b','0.2','c','0.15')),
array(CAST(1234 AS string), 'queue_disposition_val')),',') sar_vals
)
select id, str_to_map(concat_ws(',',collect_set(concat(c1.ckey,':',sar_vals[c1.i] )))) as map_col
from sartab t
lateral view posexplode(sar_keys) c1 as i,ckey
group by id;
1 {"a":"0.1","b":"0.2","c":"0.15","id_queue":"1992","queue_disposition":"queue_disposition_val"}
Time taken: 2.908 seconds, Fetched: 1 row(s)
But why is the group by id
needed? Without it there is parse exception:
FAILED: SemanticException [Error 10025]: Line 6:8 Expression not in GROUP BY key 'id'