You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
which does not allow to efficiently retrieve the fields to pass to the recursive deserialize_rows calls (i.e. one needs to linearly search for them and swap the Value). This problem would disappear if the signature was
which is actually a pretty simple change in the code, but a breaking API change. The inefficiency probably does not matter with a small number of fields.
Following issue Protryon#30, this implements the serde-like `flatten` attribute on the `Row` derive macro, allowing to compose rows as follows:
```
struct Row {
#[klickhouse(flatten)]
user: User,
credits: u32
}
let users: Vec<Row> = ch.query_collect("SELECT age, name, credits FROM ...").await?;
```
The commit also documents the serde- and clickhouse-specific attributes supported by the derive macro.
Following issue Protryon#30, this implements the serde-like `flatten` attribute on the `Row` derive macro, allowing to compose rows as follows:
```
struct Row {
#[klickhouse(flatten)]
user: User,
credits: u32
}
let users: Vec<Row> = ch.query_collect("SELECT age, name, credits FROM ...").await?;
```
The commit also documents the serde- and clickhouse-specific attributes supported by the derive macro.
Problem statement
The
Row
trait allows serializing a Rust struct to and from Clickhouse, e.g.In this example, let's assume we now want to retrieve user details and account balance in the same query. We would like to do something like
i.e. composing with the existing implementation of
User: Row
:Neither of the approaches are currently supported:
Row
is not automatically available on tuples of types implementingRow
. This would allow using(UnitValue<u32>, User)
as thequery
return type.default
,rename
,skip
...), but not flattenRather, one has to manually implement
Row
(subject to some issues described below).Implementation possibilities
Row
on composed typesFor the first approach, one would implement
Row
on tuples implementingRow
.For
(T1, ..., Tn)
, one would either:T1
andT2
.flatten
supportFor serialization and deserialization, one would:
{serialize, deserialize}_row
of the subfield, setting (resp. retrieving) the respective fields.One minor annoyance is the signature
which does not allow to efficiently retrieve the fields to pass to the recursive
deserialize_rows
calls (i.e. one needs to linearly search for them and swap theValue
). This problem would disappear if the signature waswhich is actually a pretty simple change in the code, but a breaking API change. The inefficiency probably does not matter with a small number of fields.
Subfield addressing
Another approach is to allow deriving
where the
User
fields are serialized and deserialized with auser
prefix, e.g.Either implicitly, or with another attribute on the
user: User
field.Comments?
I have a working draft for the
flatten
approach, and I might have a go at the tuple approach too.Before cleaning this up and submitting a PR, I wanted to ask whether you had any comments or thoughts about this?
I only recently started using clickhouse and this (very nice) crate, and I might be missing some subtleties.
The text was updated successfully, but these errors were encountered: