clickhouse-rs
clickhouse-rs copied to clipboard
Nested fields?
Hello! Please, how do I send nested fields to clickhouse? I have a table like this:
CREATE TABLE IF NOT EXISTS stats (
created DateTime('UTC'),
data Nested (
latency Float32,
sum_packets_lost UInt32,
sum_packets_transmitted UInt32,
established_conns UInt8,
non_established_conns UInt8
)
) ENGINE = ReplacingMergeTree
PRIMARY KEY(created)
I used to use the row!
macro, but since I have several Nested fields, which must be inserted only in some cases, I'm using now the row.push()
method:
let mut block = Block::new();
for... {
let mut row = Vec::new();
row.push(String::from("created"), Value::from(123123));
if data.is_ok() {
row.push(String::from("data.latency"), Value::from(1.23));
...
}
block.push(row)?;
}
Well, with this I get an error (don't know if it is in clickhouse db or this lib):
From SQL error: `SqlType::Float32 cannot be cast to Array(Float32).`
If I try to include a vec:
row.push(String::from("stats.latency"), vec![Value::from(1.23)]);
It doesn't compile:
error[E0277]: the trait bound `clickhouse_rs::types::Value: From<Vec<f32>>` is not satisfied
Can you help me? Thank you.
Hello @suharev7, please would you have some guidance here? I may be missing something trivial or mis-using the lib... Thanks.
@rsalmei Did you find a solution here?
Unfortunately, I didn't @JosephRedfern. I ended up avoiding anything more advanced, like Nested or Arrays, since I've never got a response here.