这是我的问题,我在配置单元中有一个表,有2列,id和一个双值数组。我想为给定的用户跨行添加双值。数据就是这样的。每个数组的长度都相同,大于100,但为了简单起见,我这里只给出了3个数组。
+--------+--------------------------
| id | value |
+--------+--------------------------+
| 1 | [0.03,0.15,-0.03] |
| 1 | [-0.2,0.11,-0.16] |
| 1 | [0.03,0.15,-0.03] |
| 2 | [0.02,0.01,0.05] |
| 2 | [0.1,0.03,0.3] |
+--------+--------------------------+
我期待的答案是
+--------+--------------------
| id | value |
+--------+---------------------
| 1 | [0.4,0.41,-0.22] |
| 2 | [0.12,0.04,0.35] |
+--------+---------------------
如何使用配置单元查询执行此操作?提前谢谢
更新:这里是我用来得到一个解决方案。但我在寻找更好的解决办法。
SELECT id, concat_ws(',', collect_list(CAST(val_new AS STRING))) as val_fin FROM (SELECT id, avg(valueid) as val_new from (SELECT id, valueid, index from user_interest_profiles.clicked_articles LATERAL VIEW POSEXPLODE(split(vector,'\\,')) value AS index, valueid )x GROUP BY id, index)x GROUP BY id;
我使用的实现是:
用索引分解数组
用group by id和index平均值
使用collect\u list跨行连接值
暂无答案!
目前还没有任何答案,快来回答吧!