-
Notifications
You must be signed in to change notification settings - Fork 101
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 the FixedString
type
#49
Comments
AFAIK you can't write FixedStrings like String - CH wire format doesn't expect a size header like how Strings are serialized. You'll have to manually write each byte in the FixedString using repeated calls to See https://github.com/loyd/clickhouse.rs/blob/d5926b12007cd20348ce945b074442395e5fd1d2/src/rowbinary/ser.rs#L69 - you can't have the serializer write out the length. |
that means this crate do not support the CH base type FixedString ? |
Well, it does, but it's similar to the discussion for #48 - you'll need to use |
All right, Now I'm adding
|
Any updates about |
So I've implemented the following, use clickhouse::Row;
use serde::Serialize;
pub mod fixed_string {
use serde::{ser::Serializer, Serialize};
pub fn serialize<S: Serializer, const LEN: usize>(
str: &str,
ser: S,
) -> Result<S::Ok, S::Error> {
let str_bytes = str.as_bytes();
if str_bytes.len() >= LEN {
log::debug!(
"[Ser] length are more than equal to {}, serialized to: `{:?}`",
LEN,
&str_bytes[..LEN]
);
str_bytes[..LEN].serialize(ser)
} else {
let mut padding: [u8; LEN] = [0; LEN];
padding[..str_bytes.len()].copy_from_slice(str_bytes);
log::debug!(
"[Ser] length are less than equal to {}, serialized to: `{:?}`",
LEN,
padding
);
padding.serialize(ser)
}
}
}
#[derive(Debug, Row, Serialize)]
pub struct Test {
#[serde(serialize_with = "fixed_string::serialize::<_, 8>")]
pub id: String,
} Then do a test on Clickhouse 23.11, it still results in the following error,
Is there an extra byte sent by the library? Since the error comes on the first row, but it indicated there's a second row. Also here are the sql file I use to make the table, create or replace table events_dev.test ( id FixedString(8) ) engine = MergeTree() primary key (id) Anyone can maybe steer me to the right direction here? |
Also I've busted out Is there any way to basically make the library ignore adding the length to the serialized string? (@loyd) Or maybe it's part of serde implementation? p.s. If you're curios about the packet, here's the dump
|
@fauh45 sorry for late response. You should use https://docs.rs/serde/latest/serde/trait.Serializer.html#tymethod.serialize_tuple or multiple |
Somehow I am able to use it. I am decoding it to a |
I am struggling hard with this. Either serialization is broken or deserialization. It would be awesome if someone could share the serde code for any FixedString. |
It seems more than 1 FixedString not work.
demo code:
the panic information:
the call stack point to
insert.end().await.unwrap();
rust version:
clickhouse version:
The text was updated successfully, but these errors were encountered: