1

我有一个Stream如下所示的目的地,例如:

Company_ID      Product      User_Tag    Count
   123            P1             T1        15
   123            P1             T2        10
   123            P1             T3        10

我想要最终输出如下:

Company_ID      Product       User_Tag    Count
   123            P1         [T1,T2,T3]    35

我尝试使用listaggonUser_Tag但我收到一条错误消息no function signature found。这在 AWS Kinesis SQL 流数据上是否可行?

4

1 回答 1

1

SQL - 数组聚合

SELECT company_id,
       product,
       Array_agg(user_tag),
       Sum(count)
FROM   stream
GROUP  BY company_id,
          product; 

 company_id | product | array_agg  | sum
------------+---------+------------+-----
        123 | P1      | {T1,T2,T3} |  35

SQL - 字符串聚合:

SELECT company_id,
       product,
       String_agg(user_tag, ','),
       Sum(count)
FROM   stream
GROUP  BY company_id,
          product; 
    

   company_id | product | string_agg | sum
------------+---------+------------+-----
        123 | P1      | T1,T2,T3   |  35 
 

编辑 演示链接。

于 2022-01-31T05:02:09.057 回答