From e6b6888b90f730518e5fe3aa132a628d88f5ea50 Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Mon, 28 Sep 2026 17:09:57 +0300 Subject: [PATCH] fix(schema): fix format mismatch in getObjectMetadata and getServerStats scalar queries handle_get_server_stats and handle_get_object_metadata requested SELECT version(), SELECT uptime() and SHOW CREATE TABLE with FORMAT JSONCompactEachRow (a single data line, no headers), then parsed the response with parse_compact_output, which unconditionally expects FORMAT JSONCompactEachRowWithNamesAndTypes (names line + types line + data lines). Against a real ClickHouse server this always failed to parse, silently falling back to "ClickHouse"/0/"" defaults. Switch all three queries to FORMAT JSONCompactEachRowWithNamesAndTypes so parse_compact_output can read them, and update the version/uptime network-error fallbacks to the same shape. Closes #57 --- src/mapper/row_compact.rs | 22 ++++++++++++++++++++++ src/rpc/handlers/schema.rs | 26 +++++++++++++++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/mapper/row_compact.rs b/src/mapper/row_compact.rs index 99012c0..64440ee 100644 --- a/src/mapper/row_compact.rs +++ b/src/mapper/row_compact.rs @@ -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(); diff --git a/src/rpc/handlers/schema.rs b/src/rpc/handlers/schema.rs index 9ad3c19..51036b8 100644 --- a/src/rpc/handlers/schema.rs +++ b/src/rpc/handlers/schema.rs @@ -322,13 +322,29 @@ pub async fn handle_get_server_stats(params: Option) -> Result) -> Result