如何使用 ClickHouse 窗口漏斗模式?
Posted
技术标签:
【中文标题】如何使用 ClickHouse 窗口漏斗模式?【英文标题】:How to use ClickHouse windowFunnel mode? 【发布时间】:2021-10-26 10:54:34 【问题描述】:我想在 ClickHouse 中使用windowFunnel() 函数。这是我的查询:
SELECT level,
count() AS count
FROM (
SELECT device_id,
windowFunnel(6000000000000)(creation_time, event_id = 100,
event_id = 101) AS level
FROM event
WHERE ((creation_time >= '2021-08-01')
AND (creation_time <= '2021-09-30'))
AND (event_id in [100,101])
GROUP BY device_id)
GROUP BY level
ORDER BY level ASC;
我希望 ClickHouse 返回不干预其他事件的事件序列。例如,如果序列是 100 => 102 => 101,它应该停止在 102 处找到 100 => 101。 ClickHouse 文档在 windowFunnel strict_order 模式下被认为是这个特性。但是当我以这种方式使用它时:
SELECT level,
count() AS count
FROM (
SELECT device_id,
windowFunnel(6000000000000, ['strict_order'])(creation_time, event_id = 100,
event_id = 101) AS level
FROM event
WHERE ((creation_time >= '2021-08-01')
AND (creation_time <= '2021-09-30'))
AND (event_id in [100,101])
GROUP BY device_id)
GROUP BY level
ORDER BY level ASC;
ClickHouse 抛出错误提示:
Code: 170, e.displayText() = DB::Exception: Bad get: has Array, requested String (version 21.7.2.7 (official build))
我不知道如何在 windowFunnel() 函数中使用模式? 任何帮助将不胜感激。
【问题讨论】:
【参考方案1】:我终于可以找到如何使用windowsFunnel()
模式查询 CH。我应该删除数组:
SELECT level,
count() AS count
FROM (
SELECT device_id,
windowFunnel(6000000000000, 'strict_order')
(creation_time, event_id = 100,
event_id = 101) AS level
FROM event
WHERE ((creation_time >= '2021-08-01')
AND (creation_time <= '2021-09-30'))
AND (event_id in [100,101])
GROUP BY device_id)
GROUP BY level
ORDER BY level ASC;
我只是想不通为什么 CH 文档在 windowsFunnel()
语法中使用 [],我认为这里有一个错误:
windowFunnel(window, [mode, [mode, ... ]])(timestamp, cond1, cond2, ..., condN)
【讨论】:
没有错。 en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form 选项可以通过方括号 [ ... ] 表示。也就是说,在方括号中设置的所有内容可能只出现一次,或者根本不出现以上是关于如何使用 ClickHouse 窗口漏斗模式?的主要内容,如果未能解决你的问题,请参考以下文章