Skip to content

Commit d3b3f8b

Browse files
azatclaude
andcommitted
Delegate SQLQueryView string-like columns to column_as_string
The view duplicated the Enum8/Enum16 name resolution and UUID formatting that column_as_string already does for the interpreter readers. Teach column_as_string to format UUID too and fold the view's String, LowCardinality(String), Enum8/16 and UUID arms into one fallback that calls it. Unsupported types now surface an error from the String read instead of unreachable!() panicking the TUI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 189621f commit d3b3f8b

2 files changed

Lines changed: 12 additions & 31 deletions

File tree

src/interpreter/clickhouse.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ use std::str::FromStr;
2323

2424
pub type Columns = Block<Complex>;
2525

26-
// clickhouse-rs reads an Enum column as its bare integer (FromSql drops the name mapping), so
27-
// block.get::<String> fails on it; resolve the name from the Vec carried by the column type.
28-
// String and LowCardinality(String) fall through to a plain String read (get coerces LC).
26+
// clickhouse-rs reads an Enum column as its bare integer (FromSql drops the name mapping) and a
27+
// UUID as uuid::Uuid, so block.get::<String> fails on both; resolve the enum name from the Vec
28+
// carried by the column type and format the UUID. String and LowCardinality(String) fall through
29+
// to a plain String read (get coerces LC).
2930
pub fn column_as_string<K: ColumnType>(block: &Block<K>, row: usize, name: &str) -> Result<String> {
3031
let column = block
3132
.columns()
@@ -41,6 +42,7 @@ pub fn column_as_string<K: ColumnType>(block: &Block<K>, row: usize, name: &str)
4142
Ok(match column.sql_type() {
4243
SqlType::Enum8(values) => name_of(&values, block.get::<Enum8, _>(row, name)?.internal()),
4344
SqlType::Enum16(values) => name_of(&values, block.get::<Enum16, _>(row, name)?.internal()),
45+
SqlType::Uuid => block.get::<uuid::Uuid, _>(row, name)?.to_string(),
4446
_ => block.get::<String, _>(row, name)?,
4547
})
4648
}

src/view/sql_query_view.rs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ use std::sync::{Arc, Mutex};
44
use anyhow::{Result, anyhow};
55
use size::{Base, SizeFormatter, Style};
66

7-
use crate::interpreter::{BackgroundRunner, ContextArc, WorkerEvent, clickhouse::Columns};
7+
use crate::interpreter::{
8+
BackgroundRunner, ContextArc, WorkerEvent,
9+
clickhouse::{Columns, column_as_string},
10+
};
811
use crate::view::TableViewItem;
912
use crate::view::table_view::TableView;
1013
use crate::wrap_impl_no_move;
1114
use chrono::{DateTime, Local};
1215
use chrono_tz::Tz;
13-
use clickhouse_rs::types::{Enum8, Enum16, SqlType};
16+
use clickhouse_rs::types::SqlType;
1417
use cursive::Cursive;
1518
use cursive::theme::Color;
1619
use cursive::utils::markup::StyledString;
@@ -230,31 +233,6 @@ impl SQLQueryView {
230233
.find(|c| c.name() == column)
231234
.ok_or(anyhow!("Cannot get {} column", column))?;
232235
let field = match sql_column.sql_type() {
233-
SqlType::String => Field::String(block.get::<_, _>(i, column)?),
234-
// block.get coerces LowCardinality to its inner type
235-
SqlType::LowCardinality(SqlType::String) => {
236-
Field::String(block.get::<_, _>(i, column)?)
237-
}
238-
SqlType::Uuid => {
239-
Field::String(block.get::<uuid::Uuid, _>(i, column)?.to_string())
240-
}
241-
// Enum values only carry the integer; the name mapping lives in the type
242-
SqlType::Enum8(values) => {
243-
let v = block.get::<Enum8, _>(i, column)?.internal();
244-
let name = values
245-
.iter()
246-
.find(|(_, k)| *k == v)
247-
.map_or_else(|| v.to_string(), |(name, _)| name.clone());
248-
Field::String(name)
249-
}
250-
SqlType::Enum16(values) => {
251-
let v = block.get::<Enum16, _>(i, column)?.internal();
252-
let name = values
253-
.iter()
254-
.find(|(_, k)| *k == v)
255-
.map_or_else(|| v.to_string(), |(name, _)| name.clone());
256-
Field::String(name)
257-
}
258236
SqlType::Float64 => Field::Float64(block.get::<_, _>(i, column)?),
259237
SqlType::Float32 => Field::Float32(block.get::<_, _>(i, column)?),
260238
SqlType::UInt64 => Field::UInt64(block.get::<_, _>(i, column)?),
@@ -270,7 +248,8 @@ impl SQLQueryView {
270248
.get::<DateTime<Tz>, _>(i, column)?
271249
.with_timezone(&Local),
272250
),
273-
_ => unreachable!("Type for column {} not implemented", column),
251+
// String, LowCardinality(String), Enum8/16 and UUID all render as text
252+
_ => Field::String(column_as_string(&block, i, column)?),
274253
};
275254
row.0.push(field);
276255
}

0 commit comments

Comments
 (0)