Reproduction of potentially-incorrect Vec<Vec<u8>> encoding with query_values
rw opened this issue · comments
Following up on #340, here is a test case to show a potential encoding issue with Vec<Vec<u8>>
using query_values!
. I'm not an expert on the CQL binary protocol, but it seems noteworthy to me that each byte in the Vec<u8>
items is treated, I think, as a 1-element vector. I'm using cdrs 2.3.3.
cc @AlexPikalov
/// output:
///
/// strings: ["abc", "def"]
/// qv_strings: SimpleValues([Value { body: [0, 0, 0, 2, 0, 0, 0, 3, 97, 98, 99, 0, 0, 0, 3, 100, 101, 102], value_type: Normal(18) }])
/// bytestrings: [[97, 98, 99], [100, 101, 102]]
/// qv_bytestrings: SimpleValues([Value { body: [0, 0, 0, 2, 0, 0, 0, 19, 0, 0, 0, 3, 0, 0, 0, 1, 97, 0, 0, 0, 1, 98, 0, 0, 0, 1, 99, 0, 0, 0, 19, 0, 0, 0, 3, 0, 0, 0, 1, 100, 0, 0, 0, 1, 101, 0, 0, 0, 1, 102], value_type: Normal(50) }])
fn main() {
let strings: Vec<String> = vec!["abc".into(), "def".into()];
let bytestrings: Vec<Vec<u8>> = vec!["abc".to_string().into(), "def".to_string().into()];
let qv_strings = cdrs::query_values!(strings.clone());
let qv_bytestrings = cdrs::query_values!(bytestrings.clone());
println!("strings: {:?}", strings);
println!("qv_strings: {:?}", qv_strings);
println!("bytestrings: {:?}", bytestrings);
println!("qv_bytestrings: {:?}", qv_bytestrings);
}
Could you please let me know which type for a given column do you have in a Cassandra? Is this some sort of text or blob?
@AlexPikalov all blobs!
@AlexPikalov this reproduction doesn't use Cassandra at all though. I'm just showing a potential encoding issue.
FWIW, I suspect that query_values!
is using one of the blanket impls incorrectly: like converting the inner u8
elements instead of the entire Vec<u8>
as one item.
@AlexPikalov If the blanket impls are the cause of my problem, perhaps there's a type hint I can provide somewhere to make it work? That would be a quick fix.
@AlexPikalov Or, I can encode them manually?
@AlexPikalov That works, thank you! I suggest we document this somewhere, because I didn't know how to fix this, even though the fix was simple.
@rw
Makes sense to document it. 👍