【问题标题】:greenplum STRING_AGG functions convert to hiveSQLgreenplum STRING_AGG 函数转换为 hiveSQL
【发布时间】:2021-10-20 11:54:51
【问题描述】:

我们必须将 greenplum sql 迁移到 hivesql 并且下面的查询不支持 string_agg 关键字。请帮助我们。

select data_date, subscriber_id, msisdn, product, validity,
    STRING_AGG(d0,'xx') d0, STRING_AGG(d1,'') d1, STRING_AGG(d2,'') d2, STRING_AGG(d3,'') d3, STRING_AGG(d4,'') d4,
    STRING_AGG(d5,'') d5, STRING_AGG(d6,'') d6, STRING_AGG(d7,'') d7, STRING_AGG(d8,'') d8, STRING_AGG(d9,'') d9, STRING_AGG(d10,'') d10,
    STRING_AGG(d11,'') d11
from tmp_subscription_base_02
group by 1,2,3,4,5

hivesQL 中不支持 string_agg。

【问题讨论】:

    标签: sql hive concatenation hiveql greenplum


    【解决方案1】:

    string_agg(expression, delimiter) 聚合函数可以在 Hive 中替换为

    concat_ws(delimiter,collect_list(cast(expression as string))
    

    或者如果您需要连接 DISTINCT 值:

    concat_ws(delimiter,collect_set(cast(expression as string))
    

    注意:如果expression是字符串类型,cast(expression as string)不是必须的,直接使用expression

    【讨论】:

    • 请验证以下查询是否正确
    • 选择data_date、subscriber_id、msisdn、product、validity、concat_ws('xx',collect_list(cast(d0 as string))) d0, concat_ws('',collect_list(cast(d1 as string) )) d1, concat_ws('',collect_list(cast(d2 as string))) d2, concat_ws('',collect_list(cast(d3 as string)))
    • @karthikelavan 是的,它应该可以工作。
    • 非常感谢您的帮助,是的,它工作正常
    猜你喜欢
    • 1970-01-01
    • 2021-11-15
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 2021-05-31
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多