How to concat uncertain keys together in hive?

38 Views Asked by At

Got source data like this. And all the keys are uncertain.

{k1: 0.5, k2: 0.6, k3: 0.3}

I want to concat(all_keys, ',') if value > 0.5 order by value desc. The correct result is 'k2,k1'

How should I do that in hive?

1

There are 1 best solutions below

0
Raid On

Assuming your data is stored under table test1 as column data.

select concat_ws(',',collect_list(key)) res 
  from (select key, vals
          from (select explode(data) as (key,vals)
                  from test1) sq1 
         where vals > 0.5 
       sort by vals desc 
       ) a;