如何正确使用ClickHouse windowFunnel函数的strict_order模式?
问题原因及解决方案
报错根因
你使用的21.7.2.7版本ClickHouse中,windowFunnel的模式参数暂不支持数组类型传入,需要将模式作为独立的字符串参数逐个传递,不需要包裹方括号。你写法里的['strict_order']传入了数组,触发了类型不匹配错误。
正确写法
1. 修正参数格式
将模式参数的方括号去掉,直接传入字符串即可:
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' GROUP BY device_id) GROUP BY level ORDER BY level ASC;
注意:这里需要删除原查询中
event_id in [100,101]的过滤条件。如果提前过滤掉了102这类其他事件,windowFunnel无法感知到中间存在其他事件,strict_order模式不会生效。
2. 多模式传递规则
- 21.8及更早版本:多个模式直接作为独立参数追加即可,示例:
windowFunnel(窗口时长, 'strict_order', 'strict_increasing') - 21.9及更高版本:支持数组形式传入多个模式,示例:
windowFunnel(窗口时长, ['strict_order', 'strict_increasing'])
内容的提问来源于stack exchange,提问作者Maedeh Sh
相关产品推荐
相关产品推荐

