【发布时间】:2023-04-07 12:14:01
【问题描述】:
我们为 Clickhouse 创建了一个平面表,并试图从该表中获取记录以创建一个物化视图。逻辑是如果 e_id 为 null,则记录为“TypeB”,如果 e_id 不为 null,则记录为“TypeA”。 TypeA 和 TypeB 记录都将具有相同的 p_id 和 s_id。我们希望为每个 p_id+s_id 组合创建一条记录。
下面给出的查询适用于过滤器(p_id = 1 和 s_id = 1)但没有过滤器 - 例外是“DB::Exception:标量子查询返回多于一行” 是否可以在 ClickHouse 中执行此操作? 是否可以使用这样的查询创建物化视图?
select p_id,s_id,
groupArray(e_id),
groupArray(name),
(select groupArray(name)
from flat_table
where e_id is null and p_id =1 and s_id = 1
group by p_id,s_id) as typeB
from flat_table
where e_id is not null and p_id =1 and s_id = 1
group by p_id,s_id;
/*
This what the table looks like:
Flat_table
p_id s_id e_id name
1 1 1 Jake
1 1 2 Bob
1 1 null Barby
1 1 null Ella
This is expected result:
p_id s_id e_id typeA typeB
1 1 [1,2] [Jake,Bob] [Barby,Ella]
*/
【问题讨论】:
标签: clickhouse