suharev7 / clickhouse-rs

Asynchronous ClickHouse client library for Rust programming language.
MIT License
324 stars 121 forks source link

Nested fields? #180

Closed rsalmei closed 4 months ago

rsalmei commented 2 years 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 2 years ago

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

JosephRedfern commented 6 months ago

@rsalmei Did you find a solution here?

rsalmei commented 6 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 4 months ago

@rsalmei Nested type isn't supported

rsalmei commented 4 months 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 4 months 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