From c4ed11aca9f2575a2bd6083c6d4d8aeef849726d Mon Sep 17 00:00:00 2001 From: Benjamin Naecker Date: Thu, 7 Nov 2024 16:26:28 -0800 Subject: [PATCH] Use ClickHouse native client to read database tables - Most of the work to use the native client during schema updates was already done in #6943. One annoyingly small exception is the code that lists the tables in the database, which we use for expunging old timeseries schema from all the relevant tables. This switches to using the native client to list tables too. - Fixes #7015 --- oximeter/db/src/client/mod.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/oximeter/db/src/client/mod.rs b/oximeter/db/src/client/mod.rs index 3fdee90858a..82910b99a75 100644 --- a/oximeter/db/src/client/mod.rs +++ b/oximeter/db/src/client/mod.rs @@ -1437,9 +1437,34 @@ impl Client { if replicated { sql.push_str(" AND engine = 'ReplicatedMergeTree'"); } - self.execute_with_body(sql).await.map(|(_summary, body)| { - body.lines().map(ToString::to_string).collect() - }) + let col = self + .execute_with_block(&sql) + .await + .and_then(|result| { + result.data.ok_or_else(|| { + Error::Database(String::from( + "Query for database tables should have returned \ + a data block, but none was found", + )) + }) + })? + .columns + .swap_remove("name") + .ok_or_else(|| { + Error::Database(String::from( + "Query for database tables should have returned \ + a column with name 'names', but none was found", + )) + })?; + let ValueArray::String(names) = col.values else { + return Err(Error::Database(format!( + "Query for database tables should have returned \ + an array of string table names, but the column \ + has type: '{}'", + col.data_type, + ))); + }; + Ok(names) } }