Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/mapper/row_compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ mod tests {
assert_eq!(res.statistics.elapsed_ms, 15);
}

#[test]
fn test_parse_compact_output_scalar_row() {
// Regression for issue #57: scalar introspection queries
// (SELECT version(), SELECT uptime(), SHOW CREATE TABLE) must be
// requested with FORMAT JSONCompactEachRowWithNamesAndTypes so this
// parser's fixed 2-header-line assumption holds; a bare
// JSONCompactEachRow response has no names/types lines and would
// previously fail with "missing names or types row".
let version_output = r#"["version()"]
["String"]
["24.3.1.2452"]"#;
let res = parse_compact_output(version_output, 0).unwrap();
assert_eq!(res.rows.len(), 1);
assert_eq!(res.rows[0][0], json!("24.3.1.2452"));

let uptime_output = r#"["uptime()"]
["UInt32"]
[123456]"#;
let res = parse_compact_output(uptime_output, 0).unwrap();
assert_eq!(res.rows[0][0].as_u64(), Some(123456));
}

#[test]
fn test_parse_compact_output_empty() {
let res = parse_compact_output("", 5).unwrap();
Expand Down
26 changes: 21 additions & 5 deletions src/rpc/handlers/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,29 @@ pub async fn handle_get_server_stats(params: Option<Value>) -> Result<Value, Dri
}

let version_text = client
.post_sql("SELECT version() FORMAT JSONCompactEachRow", |_| {})
.post_sql(
"SELECT version() FORMAT JSONCompactEachRowWithNamesAndTypes",
|_| {},
)
.await
.unwrap_or_else(|_| r#"["ClickHouse unknown"]"#.to_string());
.unwrap_or_else(|_| {
r#"["version()"]
["String"]
["unknown"]"#
.to_string()
});
let uptime_text = client
.post_sql("SELECT uptime() FORMAT JSONCompactEachRow", |_| {})
.post_sql(
"SELECT uptime() FORMAT JSONCompactEachRowWithNamesAndTypes",
|_| {},
)
.await
.unwrap_or_else(|_| r#"[0]"#.to_string());
.unwrap_or_else(|_| {
r#"["uptime()"]
["UInt32"]
[0]"#
.to_string()
});

let mut version_str = "ClickHouse".to_string();
if let Ok(parsed) = crate::mapper::row_compact::parse_compact_output(&version_text, 0)
Expand Down Expand Up @@ -421,7 +437,7 @@ pub async fn handle_get_object_metadata(params: Option<Value>) -> Result<Value,
}

let ddl_sql = format!(
"SHOW CREATE TABLE {}.{} FORMAT JSONCompactEachRow",
"SHOW CREATE TABLE {}.{} FORMAT JSONCompactEachRowWithNamesAndTypes",
crate::utils::sql_escape::quote_identifier(db_name),
crate::utils::sql_escape::quote_identifier(tbl_name)
);
Expand Down
Loading