如何删除配置单元数组中值为零的元素
How to remove the elements with value as zero in hive array
我在配置单元中有一个数组列,它将包含 7 个数字。
例如:[32,4,0,43,23,0,1]
我希望我的输出是 [32,4,43,23,1]
(删除所有零元素)
有人帮我完成这个吗?
爆阵,过滤,再收集
演示:
with mydata as (
select array(32,4,0,43,23,0,1) as initial_array
)
select initial_array, collect_set(element) as result_array
from
(
select initial_array, e.element
from mydata
lateral view outer explode(initial_array)e as element
) s
where element != 0
group by initial_array
结果:
initial_array result_array
[32,4,0,43,23,0,1] [32,4,43,23,1]
我在配置单元中有一个数组列,它将包含 7 个数字。
例如:[32,4,0,43,23,0,1]
我希望我的输出是 [32,4,43,23,1]
(删除所有零元素)
有人帮我完成这个吗?
爆阵,过滤,再收集
演示:
with mydata as (
select array(32,4,0,43,23,0,1) as initial_array
)
select initial_array, collect_set(element) as result_array
from
(
select initial_array, e.element
from mydata
lateral view outer explode(initial_array)e as element
) s
where element != 0
group by initial_array
结果:
initial_array result_array
[32,4,0,43,23,0,1] [32,4,43,23,1]