Protryon / klickhouse

Rust crate for accessing Clickhouse
Apache License 2.0
88 stars 21 forks source link

Support serialize rust `Vec<u8>` to clickhouse `String`/`FixedString` #21

Closed c0mm4nd closed 1 year ago

c0mm4nd commented 1 year ago

Current (v0.8.8) is broken when rust type is Vec<u8> or u8 slice.

Storing hash with hex encoded works fine with FixedString(64) , but when trying to store a hash to a FixedString(32) (to save space)

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: TypeParseError("could not assign value 'Array([UInt8(212), UInt8(229), UInt8(103), UInt8(64), UInt8(248), UInt8(118), UInt8(174), UInt8(248), UInt8(192), UInt8(16), UInt8(184), UInt8(106), UInt8(64), UInt8(213), UInt8(245), UInt8(103), UInt8(69), UInt8(161), UInt8(24), UInt8(208), UInt8(144), UInt8(106), UInt8(52), UInt8(230), UInt8(154), UInt8(236), UInt8(140), UInt8(13), UInt8(177), UInt8(203), UInt8(143)])' to type 'FixedString(32)'")', src/main.rs:311:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace 
Protryon commented 1 year ago

Fixed in 0.9.0, see release notes: https://github.com/Protryon/klickhouse/releases/tag/v0.9.0

c0mm4nd commented 1 year ago

It seems buggy. Some chars are replaced by EF BF BD (the utf8 for the malformed char). e.g. 0x00208c5d9fe8b48dd1857ba48d4cade2f4328ebeaa792022a7b32afc176dd012 image 00 20works, but 8c is repaced by utf8 EF BF BD, and then 5d works, 9f is also replaced by EF BF BD...

@Protryon

Protryon commented 1 year ago

Will take a look at shortly.

Protryon commented 1 year ago

@c0mm4nd I wasn't able to reproduce with the attached example, can you tell me:

My attempt at reproduction: https://github.com/Protryon/klickhouse/blob/master/klickhouse/tests/test_raw_string.rs Feel free to PR that into a minimal reproducible example as well.

EDIT: I also just ran this after that example test, in the clickhouse-client CLI tool:

localhost :) select hex(raw_string) from test_raw_string;

SELECT hex(raw_string)
FROM test_raw_string

Query id: 642f3981-79c6-47d6-a1ce-113fbf77d759

┌─hex(raw_string)─┐
│ 00208C5D9F      │
└─────────────────┘

1 row in set. Elapsed: 0.002 sec. 

Which is correct.

c0mm4nd commented 1 year ago

Thanks for your fast reply. Results in clickhouse-client are all correct in my test right now. So it might be dbeaver's problem or my mistake on GUI. Very sorry wasting your time.

Protryon commented 1 year ago

No worries. Happy to help.