ClickHouse物化视图使用pointInPolygon关联报错问题咨询
问题:ClickHouse物化视图中使用pointInPolygon关联报错的解决
用户需要用物化视图处理表数据,创建了如下表结构及物化视图:
CREATE TABLE test.zone ( `id` UInt32, `district` String, `city` String, `polygon` Polygon ) ENGINE = Memory; CREATE TABLE test.source1 ( id UInt32, point Point ) ENGINE = Null; CREATE TABLE test.by_zone1 ( `id` UInt32, `zone_id` UInt32, `count` UInt32 ) ENGINE = AggregatingMergeTree ORDER BY (zone_id, id); CREATE MATERIALIZED VIEW test.mv_by_zone TO test.by_zone1 AS SELECT z.id AS zone_id, s.id AS id, count(s.id) AS count FROM test.`source1` s JOIN test.`zone` z ON pointInPolygon(s.point, z.polygon) GROUP BY z.id, s.id;
创建物化视图时出现如下错误:
SQL Error [403] [07000]: Code: 403. DB::Exception: JOIN test.source1 AS __table1 ALL INNER JOIN test.zone AS __table2 ON pointInPolygon(__table1.point, __table2.polygon) join expression contains column from left and right table, you may try experimental support of this feature by `SET allow_experimental_join_condition = 1`. (INVALID_JOIN_ON_EXPRESSION) (version 24.5.1.1065 (official build))
用户疑问:是否在此场景下确实无法使用pointInPolygon,还是查询语句存在错误?
解答
- 不是不能用
pointInPolygon,而是ClickHouse默认限制了关联条件同时包含左右表字段的非等值JOIN,报错信息已经明确说明了这一点。 - 解决方式:开启实验性支持开关
allow_experimental_join_condition = 1,可以在创建物化视图前执行语句:SET allow_experimental_join_condition = 1;,也可以将该参数配置到ClickHouse全局配置文件中(如config.xml)。 - 注意:该参数属于实验性特性,生产环境使用前需充分测试,确保满足业务稳定性需求。
- 你的查询语句逻辑本身没有错误,只是触发了ClickHouse默认不允许的非等值JOIN场景。
内容的提问来源于stack exchange,提问作者Егор Лебедев
相关产品推荐
相关产品推荐

