Skip to content

Commit 5660966

Browse files
authored
Use ClickHouse native client to read database tables (#7016)
- 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
1 parent c4c4d96 commit 5660966

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

oximeter/db/src/client/mod.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,9 +1437,34 @@ impl Client {
14371437
if replicated {
14381438
sql.push_str(" AND engine = 'ReplicatedMergeTree'");
14391439
}
1440-
self.execute_with_body(sql).await.map(|(_summary, body)| {
1441-
body.lines().map(ToString::to_string).collect()
1442-
})
1440+
let col = self
1441+
.execute_with_block(&sql)
1442+
.await
1443+
.and_then(|result| {
1444+
result.data.ok_or_else(|| {
1445+
Error::Database(String::from(
1446+
"Query for database tables should have returned \
1447+
a data block, but none was found",
1448+
))
1449+
})
1450+
})?
1451+
.columns
1452+
.swap_remove("name")
1453+
.ok_or_else(|| {
1454+
Error::Database(String::from(
1455+
"Query for database tables should have returned \
1456+
a column with name 'names', but none was found",
1457+
))
1458+
})?;
1459+
let ValueArray::String(names) = col.values else {
1460+
return Err(Error::Database(format!(
1461+
"Query for database tables should have returned \
1462+
an array of string table names, but the column \
1463+
has type: '{}'",
1464+
col.data_type,
1465+
)));
1466+
};
1467+
Ok(names)
14431468
}
14441469
}
14451470

0 commit comments

Comments
 (0)