1

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'

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
  • 1
    Guessing that `collect_set` is an aggregate function in Hive and may require group by in this case. Interested in this question and hearing the experts as I move to Hive in the near future. – Isolated Oct 25 '22 at 21:04

0 Answers0