ClickHouse / ClickHouse/clickhouse-rs

JSON type hint with Nullable fields misparsed

Open
#442 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
559
Forks
172
Avg merge
1d 19h
Merged PRs (30d)
3

Description

### Describe the bug

When trying to insert a JSON column with type hints, and at least one of the type hints is a Nullable column, the column parsing will fail with a "unknown data type" error with the last letter of the type name cut off.

### Code example

```rust
use anyhow::Context;
use clickhouse::Row;
use serde::Serialize;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let chc = clickhouse::Client::default()
.with_user("default")
.with_password("password")
.with_url("http://localhost:8123")
.with_setting("input_format_binary_read_json_as_string", "1");

chc.query("DROP TABLE IF EXISTS ch_json_test").execute().await?;

chc.query(r#"
CREATE TABLE ch_json_test (
bar JSON(test Nullable(String)),
)
ENGINE = MergeTree
"#).execute().await?;

#[derive(Row, Serialize)]
struct TestRow {
bar: String,
}

let mut ins = chc
.insert::("ch_json_test")
.await
.context("make inserter")?;

ins.write(&TestRow {
bar: "{}".to_string(),
})
.await
.context("write row")?;

ins.end().await.context("end inserter")?;

println!("success");

Ok(())
}

```

### Expected behaviour

`success` is printed

### Actual behaviour

```
Error: make inserter

Caused by:
0: error while parsing columns header from the response: type parsing error: Unknown data type: Strin
1: type parsing error: Unknown data type: Strin
```

### Configuration
#### Environment
* Client version: `0.15.2`
* OS: macOS

#### ClickHouse server
* ClickHouse Server version: 26.1.1.800
* ClickHouse Server non-default settings, if any:
* `CREATE TABLE` statements for tables involved:

```sql
CREATE TABLE ch_json_test (
bar JSON(test Nullable(String)),
)
ENGINE = MergeTree
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the provided Rust client example against ClickHouse, focusing on parsing the response columns header for a JSON column containing a Nullable(String) type hint. Trace where the type name loses its final character and inspect nearby parsing tests or entry points. Done means the example inserts successfully and no longer reports an unknown data type such as "Strin".

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.