Skip to content

Commit

Permalink
Use ClickHouse native client to read database tables (oxidecomputer#7016
Browse files Browse the repository at this point in the history
)

- Most of the work to use the native client during schema updates was
already done in oxidecomputer#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 oxidecomputer#7015
  • Loading branch information
bnaecker authored Nov 8, 2024
1 parent c4c4d96 commit 5660966
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions oximeter/db/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 5660966

Please sign in to comment.