ClickHouse / ClickHouse/clickhouse-rs

Support `serde(flatten)` attribute

Open
#264 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
559
Forks
172
Avg merge
1d 19h
Merged PRs (30d)
3

Description

### Use case

After #221 and #244, we still can't support flattened structs such as:

```rs
#[derive(Row, Serialize)]
struct Metadata {
foo: String,
bar: String,
}

#[derive(Row, Serialize)]
struct MyRow {
#[serde(flatten)]
metadata: Metadata,
data: String,
}
```

while inserting data to a table like this:

```sql
CREATE TABLE test (
foo String,
bar String,
data String
)
```

Currently, with enabled validation, it will complain about number of fields (2 in struct vs 3 in the db), cause currently it will derive only `[ "metadata", "data" ]`, and not `[ "foo", "bar", "data" ]` as it should have been.

### Describe the solution you'd like

To solve this, [derive macro](https://github.com/ClickHouse/clickhouse-rs/blob/main/derive/src/lib.rs) needs adjustments to support recursive resolution.

### Additional context

See #99, #101 for more details.

Contributor guide

Open the contributing guide

Research direction

Start in derive/src/lib.rs and trace how the derive macro resolves struct fields and produces the column list. Use the Metadata/MyRow example with the provided ClickHouse table schema to verify recursive handling of serde(flatten). Done means flattened fields resolve to ["foo", "bar", "data"] and validation no longer reports a field-count mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.