如何在Clickhouse中使用array join

how to use array join in Clickhouse

我正在尝试使用 arrayJoin()

拆分 2 个数组

我的table:

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.

我试过这个查询,但没有用。

select arrayJoin(col1)  ,arrayJoin(col2) ,col1 , col2 ,col3 from test_array;

我如何编辑查询以删除图片中突出显示的行

谢谢。

arrayJoin produces the cartesian product, to avoid it use 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,2] │ [11,22] │ Text │
│  5 │ 55 │ [5,6] │ [55,66] │ Text │
│  6 │ 66 │ [5,6] │ [55,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 │
└───────┴───────┴──────┘