如何 groupby 之后把某一列非 groupby 字段拼接起来或者放到一个数组里呢

想要 group by 的时候,对某一列非 groupby 字段不做聚合计算,只是拼接或者组合成一个向量,将组内数据全部存储。这该怎么实现?

请先 登录 后评论

1 个回答

NA

如果是 DOUBLE / INT 这种数值类型的列,可以用 toArray 函数把每个组的数据组成一个 array vector 进行存储,比如

tmp = table(rand(10, 10) as stock_id, 1..10 as amount)
select toArray(amount) as amount from tmp group by stock_id

attachments-2023-04-gYgeakGr64488067115a3.png

如果是 STRING 这种字符串类型的列,可以指定分隔符把数据拼接成一个 string,使用时,用 split 再拆分一下,比如

tmp = table(rand(10, 10) as stock_id, string(1..10) as amount)
// group by
t = select concat(amount, ";") as amount from tmp group by stock_id
// 取组内第二个字符串
tt = select amount.split(";")[1] as amount from t



请先 登录 后评论