Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for serializing maps #99

Open
AdvaithD opened this issue Jan 11, 2024 · 2 comments
Open

Support for serializing maps #99

AdvaithD opened this issue Jan 11, 2024 · 2 comments

Comments

@AdvaithD
Copy link

AdvaithD commented Jan 11, 2024

I encountered an issue with the clickhouse crate when trying to serialize a struct that uses #[serde(flatten)] to combine multiple fields into a single row. It appears that the serialize_map function is not implemented, as indicated by the todo!() macro in src/rowbinary/ser.rs at line 168, column 9.

Example:

pub struct Xyz<T: Serialize + Row> {
    #[serde(flatten)]
    pub first_field: Metadata,
    #[serde(flatten)]
    pub second_field: T,
}

From the source (src/rowbinary/ser.rs:168.9)

    #[inline]
    fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap> {
        todo!();
    }

When attempting to serialize this struct, my binary panics because serialize_map is not yet supported by the crate. Is there a workaround or a planned update to support this functionality?

@loyd
Copy link
Owner

loyd commented Jan 12, 2024

Hi, what result do you expect? What is the definition of the table and Metadata?

@Yen
Copy link

Yen commented Feb 14, 2024

Hello, I have been trying to add metadata to rows also via #[serde(flatten)]. The patten I would expect is as follows:

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

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

This would be expected to represent a row with columns (foo, bar, data).

I may be misunderstanding serde, but to me this seems like how the attribute should behave.

For reference I intend to use this in a templated struct to apply metadata (source/timestamp) to rows during their final submissions. But the example above is better to show the behaviour I expect.

Thanks

Edit: I realise this may be related to struct flattening, not map flattening as the issue relates, but this may be to do with terminology in serde.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants