【问题标题】:Exception when filtering system.parts (ClickHouse) by partition按分区过滤 system.parts (ClickHouse) 时出现异常
【发布时间】:2019-10-17 09:05:40
【问题描述】:

我尝试在表internet_users 中执行删除分区 带过滤器的查询

SELECT DISTINCT partition  
FROM system.parts 
WHERE database='users' and table='internet_users' and 
partition= '\'d2019-10-11\''

我也试过了

partition= 'd2019-10-11'
partition= toString('d2019-10-11')

过滤不起作用或出现异常

DB::Exception: Missing columns: 'd2019' while processing query: '(d2019 - 10) - 11', required columns: 'd2019', source columns: '_dummy' (version 19.15.2.2 (official build))

请帮助我编写成功工作的过滤器,ClickHouse 将过滤条件读取为字符串,而不是表达式。我无法重新创建表。

我将请求作为 URL 'query' 参数和选项发送 partition= '\'d2019-10-11\''在1.1.54385版本成功运行。

1.1.54385 版本中system.parts 中的分区列也包含'd2019-10-11',19.15.2.2 版本中system.parts 中包含d2019-10-11,同样不加引号。

SHOW CREATE TABLE users.internet_users

CREATE TABLE users.internet_users (`type` Nullable(String), `report_type_date` String) 
ENGINE = MergeTree 
PARTITION BY report_type_date ORDER BY oper_date SETTINGS index_granularity = 8192

【问题讨论】:

标签: sql http filter clickhouse


【解决方案1】:

为什么需要 report_type_date 作为 String ?真的很奇怪。

我无法重现该问题

ClickHouse client version 19.15.2.2 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 19.15.2 revision 54426.

CREATE TABLE internet_users (`type` Nullable(String), `report_type_date` String)  
ENGINE = MergeTree  PARTITION BY report_type_date ORDER BY tuple();

insert into internet_users values ('x', 'd2019-10-11');

SELECT
    partition,
    name,
    partition_id
FROM system.parts
WHERE active AND (table = 'internet_users') AND (partition = 'd2019-10-11')

┌─partition───┬─name───────────────────────────────────┬─partition_id─────────────────────┐
│ d2019-10-11 │ 1d3f8b04c0f3f7654e4391f6c7b73352_1_1_0 │ 1d3f8b04c0f3f7654e4391f6c7b73352 │
└─────────────┴────────────────────────────────────────┴──────────────────────────────────┘

partition 是一个 String ,你不需要屏蔽引号。

curl -q 'http://localhost:8123/?query=SELECT%20partition%20FROM%20system.parts%20WHERE%20active%20AND%20(table%20%3D%20%27internet_users%27)%20AND%20(partition%20%3D%20%27d2019-10-11%27)'
d2019-10-11

【讨论】:

  • 感谢您的回复。刚刚更新了问题。我使用带有查询的 http 请求和 URL 参数。
  • 我已经用 curl -q 'localhost:8123/?query=SE 更新了我的答案,也没有看到问题。
猜你喜欢
  • 2017-10-23
  • 2013-10-29
  • 2017-03-16
  • 1970-01-01
  • 1970-01-01
  • 2012-02-21
  • 1970-01-01
  • 1970-01-01
  • 2018-03-13
相关资源
最近更新 更多