首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"IN“支持联接

"IN“支持联接
EN

Stack Overflow用户
提问于 2020-04-22 09:35:30
回答 1查看 451关注 0票数 0

我们试图将戊as 连接到ClickHouse,有时ClickHouse会生成这样的查询:

代码语言:javascript
复制
select
...
from
date_dimension_table,
fact_table,
other_dimension_table
where
fact_table.fact_date = date_dimension_table.date
and date_dimension_table.calendar_year = 2019
and date_dimension_table.month_name in ('April', 'June', ...)
and fact_table.other_dimension_id = other_dimension_table.id
and other_dimension_table.code in ('code1', 'code2', ...)
group by
date_dimension_table.calendar_year,
date_dimension_table.month_name,
other_dimension_table.code;

它生成ClickHouse错误:代码: 403,e.displayText() =DB:::无效表达式用于连接。期望等于表达式,got (代码为c2) IN (‘code 1’,‘code 2’,.)。受支持的语法:联接ON Expr(table.column,.)= Expr(table.column,.) 和Expr([表.]列,.)=Expr([table.]列,.)

表用引擎: fact_table - MergeTree,双向- TinyLog.

因此,问题:

  1. 通过更改表引擎可以解决这个问题吗?不幸的是,我们不能更改查询,它是自动生成的。
  2. 如果没有,是否有计划支持在最近的将来加入ClickHouse中的 in 子句?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-04-23 13:26:44

此问题已从ClickHouse版本20.3.2.1,2020-03-12开始修复(请参阅第7314期),因此您需要升级CH。

好了!不要忘记检查所有向后不兼容的更改(请参阅变化量g)。

让我们在CH19.15.3修订版54426上重现此问题,以获得您所描述的错误:

代码语言:javascript
复制
Received exception from server (version 19.15.3):
Code: 403. DB::Exception: Received from localhost:9000. DB::Exception: Invalid expression for JOIN ON. Expected equals expression, got code IN ('code1', 'code2'). Supported syntax: JOIN ON Expr([table.]column, ...) = Expr([table.]column, ...) [AND Expr([table.]column, ...) = Expr([table.]column, ...) ...]. 

现在,在最新版本CH (20.3.7修订版54433)上执行此查询,以确保它正确工作:

代码语言:javascript
复制
docker pull yandex/clickhouse-server:latest

docker run -d --name ch_test_latest yandex/clickhouse-server:latest

docker exec -it ch_test_latest clickhouse-client

# create tables as described below
..

# execute test query
..

试验准备:

代码语言:javascript
复制
create table date_dimension_table (
    date DateTime,
    calendar_year Int32,
    month_name String
) Engine = Memory;

create table fact_table (
    fact_date DateTime,
    other_dimension_id Int32
) Engine = Memory;

create table other_dimension_table (
    id Int32,
    code String
) Engine = Memory;

测试查询:

代码语言:javascript
复制
SELECT 
    date_dimension_table.calendar_year, 
    date_dimension_table.month_name, 
    other_dimension_table.code
FROM date_dimension_table
    ,fact_table
    ,other_dimension_table
WHERE (fact_table.fact_date = date_dimension_table.date) 
    AND (date_dimension_table.calendar_year = 2019) 
    AND (date_dimension_table.month_name IN ('April', 'June')) 
    AND (fact_table.other_dimension_id = other_dimension_table.id) 
    AND (other_dimension_table.code IN ('code1', 'code2'))
GROUP BY 
    date_dimension_table.calendar_year, 
    date_dimension_table.month_name, 
    other_dimension_table.code
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61361818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档