From dea313517d1f740ebf9576edb4daee62668bd980 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 5 Jul 2024 08:23:04 +0200 Subject: [PATCH] Fix compatibility with ClickHouse without allow_experimental_analyzer=1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ClickHouse without allow_experimental_analyzer returns name of the subquery with the key when you have > 2 subqueries (odd): This is for 21.2: select a.*, b.*, c.* from (select * from system.one) as a, (select dummy as x from system.one) as b, (select dummy as y from system.one) as c ┌─a.dummy─┬─b.x─┬─c.y─┐ │ 0 │ 0 │ 0 │ └─────────┴─────┴─────┘ select a.*, b.* from (select * from system.one) as a, (select dummy as x from system.one) as b ┌─dummy─┬─x─┐ │ 0 │ 0 │ └───────┴───┘ 24.7 upstream: select a.*, b.*, c.* from (select * from system.one) as a, (select dummy as x from system.one) as b, (select dummy as y from system.one) as c ┌─a.dummy─┬─b.x─┬─c.y─┐ │ 0 │ 0 │ 0 │ └─────────┴─────┴─────┘ select a.*, b.*, c.* from (select * from system.one) as a, (select dummy as x from system.one) as b, (select dummy as y from system.one) as c settings allow_experimental_analyzer=0 ┌─a.dummy─┬─b.x─┬─c.y─┐ │ 0 │ 0 │ 0 │ └─────────┴─────┴─────┘ Fixes: 5e0d54b ("Add Inserted/Selected rows into summary") --- src/interpreter/clickhouse.rs | 80 ++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/src/interpreter/clickhouse.rs b/src/interpreter/clickhouse.rs index e8bd31f..8c44a7e 100644 --- a/src/interpreter/clickhouse.rs +++ b/src/interpreter/clickhouse.rs @@ -501,7 +501,17 @@ impl ClickHouse { ) .await?; - let get = |key: &str| block.get::(0, key).expect(key); + let get = |key: &str| { + // By subquery.column + if let Ok(value) = block.get::(0, key) { + return value; + } + + let parts = key.split(".").collect::>(); + assert!(parts.len() <= 2); + // By column + return block.get::(0, parts[parts.len() - 1]).expect(key); + }; return Ok(ClickHouseServerSummary { processes: get("processes"), @@ -513,23 +523,23 @@ impl ClickHouse { servers: get("servers"), uptime: ClickHouseServerUptime { - _os: get("os_uptime"), - server: get("uptime"), + _os: get("asynchronous_metrics.os_uptime"), + server: get("asynchronous_metrics.uptime"), }, rows: ClickHouseServerRows { - selected: get("selected_rows"), - inserted: get("inserted_rows"), + selected: get("events.selected_rows"), + inserted: get("events.inserted_rows"), }, storages: ClickHouseServerStorages { - buffer_bytes: get("storage_buffer_bytes"), - distributed_insert_files: get("storage_distributed_insert_files"), + buffer_bytes: get("metrics.storage_buffer_bytes"), + distributed_insert_files: get("metrics.storage_distributed_insert_files"), }, memory: ClickHouseServerMemory { - os_total: get("os_memory_total"), - resident: get("memory_resident"), + os_total: get("asynchronous_metrics.os_memory_total"), + resident: get("asynchronous_metrics.memory_resident"), tracked: get("memory_tracked"), tables: get("memory_tables"), @@ -537,48 +547,48 @@ impl ClickHouse { processes: get("memory_processes"), merges: get("memory_merges"), dictionaries: get("memory_dictionaries"), - primary_keys: get("memory_primary_keys"), + primary_keys: get("asynchronous_metrics.memory_primary_keys"), }, cpu: ClickHouseServerCPU { - count: get("cpu_count"), - user: get("cpu_user"), - system: get("cpu_system"), + count: get("asynchronous_metrics.cpu_count"), + user: get("asynchronous_metrics.cpu_user"), + system: get("asynchronous_metrics.cpu_system"), }, threads: ClickHouseServerThreads { - os_total: get("threads_os_total"), - os_runnable: get("threads_os_runnable"), - http: get("threads_http"), - tcp: get("threads_tcp"), - interserver: get("threads_interserver"), + os_total: get("asynchronous_metrics.threads_os_total"), + os_runnable: get("asynchronous_metrics.threads_os_runnable"), + http: get("asynchronous_metrics.threads_http"), + tcp: get("asynchronous_metrics.threads_tcp"), + interserver: get("asynchronous_metrics.threads_interserver"), pools: ClickHouseServerThreadPools { - merges_mutations: get("threads_merges_mutations"), - fetches: get("threads_fetches"), - common: get("threads_common"), - moves: get("threads_moves"), - schedule: get("threads_schedule"), - buffer_flush: get("threads_buffer_flush"), - distributed: get("threads_distributed"), - message_broker: get("threads_message_broker"), - backups: get("threads_backups"), - io: get("threads_io"), - remote_io: get("threads_remote_io"), - queries: get("threads_queries"), + merges_mutations: get("metrics.threads_merges_mutations"), + fetches: get("metrics.threads_fetches"), + common: get("metrics.threads_common"), + moves: get("metrics.threads_moves"), + schedule: get("metrics.threads_schedule"), + buffer_flush: get("metrics.threads_buffer_flush"), + distributed: get("metrics.threads_distributed"), + message_broker: get("metrics.threads_message_broker"), + backups: get("metrics.threads_backups"), + io: get("metrics.threads_io"), + remote_io: get("metrics.threads_remote_io"), + queries: get("metrics.threads_queries"), }, }, network: ClickHouseServerNetwork { - send_bytes: get("net_send_bytes"), - receive_bytes: get("net_receive_bytes"), + send_bytes: get("asynchronous_metrics.net_send_bytes"), + receive_bytes: get("asynchronous_metrics.net_receive_bytes"), }, blkdev: ClickHouseServerBlockDevices { - read_bytes: get("block_read_bytes"), - write_bytes: get("block_write_bytes"), + read_bytes: get("asynchronous_metrics.block_read_bytes"), + write_bytes: get("asynchronous_metrics.block_write_bytes"), }, - update_interval: get("metrics_update_interval"), + update_interval: get("asynchronous_metrics.metrics_update_interval"), }); }