clickhouse-rs icon indicating copy to clipboard operation
clickhouse-rs copied to clipboard

Nested fields?

Open rsalmei opened this issue 2 years ago • 3 comments

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.

rsalmei avatar Sep 19 '22 23:09 rsalmei

Hello @suharev7, please would you have some guidance here? I may be missing something trivial or mis-using the lib... Thanks.

rsalmei avatar Sep 30 '22 22:09 rsalmei

@rsalmei Did you find a solution here?

JosephRedfern avatar May 27 '24 09:05 JosephRedfern

Unfortunately, I didn't @JosephRedfern. I ended up avoiding anything more advanced, like Nested or Arrays, since I've never got a response here.

rsalmei avatar May 28 '24 17:05 rsalmei