【问题标题】:How to remove NULL from array in Athena如何从 Athena 中的数组中删除 NULL
【发布时间】:2022-01-14 13:01:41
【问题描述】:

我有这个查询聚合的数组:

select field_name1, 
       field_name2, 
       "array_agg"(DISTINCT <field_name3>) "array_agg"
from <table_name>
group by <field_name1>

问题是某些输出中有 NULL 值。

['element1', 'element2', NULL]

我们如何在聚合值时从数组中删除 NULL。

我试过了

select field_name1, 
       field_name2, 
       "array_remove"("array_agg"(DISTINCT <field_name1>), NULL) "array_agg_drop_NULL""array_agg"
from <table_name>
group by <field_name1>

但它返回所有空白的输出。

【问题讨论】:

  • 看起来像sql,所以where字段不为空

标签: sql arrays null presto athena


【解决方案1】:

你可以使用filter函数:

select filter(array['element1', 'element2', NULL], el -> el is not null) filtered

输出:

filtered
[element1, element2]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 2019-06-03
    • 2022-01-14
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    相关资源
    最近更新 更多