如何解决如何在 Clickhouse 中使用数组连接
我正在尝试使用 arrayJoin() 拆分 2 个数组
我的桌子:
create table test_array(
col1 Array(INT),col2 Array(INT),col3 String
)
engine = TinyLog;
然后我插入这些值:
insert into test_array values ([1,2],[11,22],'Text');
insert into test_array values ([5,6],[55,66],'Text');
当我在 col1 中拆分第一个数组时,结果将是这样的:
但我需要的是拆分 col1 和 col2 并将它们添加到选择中。
我试过这个查询,但没有用。
select arrayJoin(col1),arrayJoin(col2),col1,col2,col3 from test_array;
谢谢。
解决方法
arrayJoin 的串行调用产生笛卡尔积,以避免使用 ARRAY JOIN:
SELECT
c1,c2,col1,col2,col3
FROM test_array
ARRAY JOIN
col1 AS c1,col2 AS c2
/*
┌─c1─┬─c2─┬─col1──┬─col2────┬─col3─┐
│ 1 │ 11 │ [1,2] │ [11,22] │ Text │
│ 2 │ 22 │ [1,22] │ Text │
│ 5 │ 55 │ [5,6] │ [55,66] │ Text │
│ 6 │ 66 │ [5,66] │ Text │
└────┴────┴───────┴─────────┴──────┘
*/
,
另一种方式——tuple()
SELECT
untuple(arrayJoin(arrayZip(col1,col2))),col3
FROM test_array
┌─_ut_1─┬─_ut_2─┬─col3─┐
│ 1 │ 11 │ Text │
│ 2 │ 22 │ Text │
│ 5 │ 55 │ Text │
│ 6 │ 66 │ Text │
└───────┴───────┴──────┘
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。