Skip to content

Commit 09573e1

Browse files
jxomampcode-com
andcommitted
fix: handle empty ClickHouse responses for DDL statements
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019c2229-65d5-71ff-8df2-c4b58e883f7e
1 parent a1c479b commit 09573e1

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tidx: patch
3+
---
4+
5+
Fix ClickHouse DDL statement handling. DDL statements like `CREATE DATABASE` and `CREATE TABLE` return empty responses, which previously caused JSON parsing errors. Now handles empty responses gracefully.

src/clickhouse.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ impl ClickHouseEngine {
109109
let json_response = resp.text().await
110110
.map_err(|e| anyhow!("Failed to read response: {e}"))?;
111111

112+
// Handle empty responses (DDL statements like CREATE/DROP return empty)
113+
if json_response.trim().is_empty() {
114+
return Ok(QueryResult {
115+
columns: vec![],
116+
rows: vec![],
117+
row_count: 0,
118+
engine: Some("clickhouse".to_string()),
119+
query_time_ms: Some(start.elapsed().as_secs_f64() * 1000.0),
120+
});
121+
}
122+
112123
// Parse the JSON response
113124
let parsed: serde_json::Value = serde_json::from_str(&json_response)
114125
.map_err(|e| anyhow!("Failed to parse ClickHouse JSON response: {e}"))?;

0 commit comments

Comments
 (0)