hive udf函数 行转列 刷选出 null 值

with a as (
select null as c1
          ,2 as c2
          union all
          select 0 as c1
          ,2 as c2
          union all
          select 0 as c1
          ,2 as c2
          )
          select collect_set(c1)  as c_new from a group by c2

[‘0’]

select        if(  size(c_new  )=1,null,if(c_new [0]='0',c_new[1],c_new[0])) from b

null

with a as (
select 1 as c1
          ,2 as c2
          union all
          select 0 as c1
          ,2 as c2
          union all
          select 0 as c1
          ,2 as c2
          )
          select collect_set(c1)  as c_new from a group by c2

[1,0]

select        if(  size(c_new  )=1,null,if(c_new [0]=0,c_new[1],c_new[0])) from b

1