suharev7 / clickhouse-rs

Asynchronous ClickHouse client library for Rust programming language.
MIT License
322 stars 119 forks source link

Nested fields? #180

Closed rsalmei closed 1 month ago

rsalmei commented 1 year ago

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 commented 1 year ago

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

JosephRedfern commented 3 months ago

@rsalmei Did you find a solution here?

rsalmei commented 3 months ago

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

caibirdme commented 1 month ago

@rsalmei Nested type isn't supported

rsalmei commented 1 month ago

Yep @caibirdme, thanks. And this project seems abandoned. I'm not using clickhouse at work anymore, otherwise, I'd try another lib.

caibirdme commented 1 month ago

@rsalmei AFAIK, no other rust clickhouse sdk support nested type... I met with the same problem, and finally I choose to use http + jsoneachrow format