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

Need Arrays, but both row! macro and Block::column do not work

Open rsalmei opened this issue 1 year ago • 2 comments

It seems I can't insert Arrays via the row! macro, Array(Float32) in my case.

error[E0277]: the trait bound `clickhouse_rs::types::Value: std::convert::From<std::vec::Vec<f32>>` is not satisfied
   --> src/tasks/clickhouse_pusher.rs:285:18
    |
282 |           block.push(row! {
    |  ____________________-
283 | |             created: created, time_ms: utils::now_ms(),
284 | |             token: id.token.as_ref(),
285 | |             arr: ws.iter().map(|r| r.aps.len() as f32).collect::<Vec<_>>(),
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<std::vec::Vec<f32>>` is not implemented for `clickhouse_rs::types::Value`
286 | |         })?;
    | |_________- required by a bound introduced by this call
    |
    = help: the following other types implement trait `std::convert::From<T>`:
              <clickhouse_rs::types::Value as std::convert::From<&'a str>>
              <clickhouse_rs::types::Value as std::convert::From<&[u8]>>
              <clickhouse_rs::types::Value as std::convert::From<[u8; 16]>>
              <clickhouse_rs::types::Value as std::convert::From<[u8; 4]>>
              <clickhouse_rs::types::Value as std::convert::From<bool>>
              <clickhouse_rs::types::Value as std::convert::From<chrono::Date<chrono_tz::Tz>>>
              <clickhouse_rs::types::Value as std::convert::From<chrono::DateTime<chrono::Utc>>>
              <clickhouse_rs::types::Value as std::convert::From<chrono::DateTime<chrono_tz::Tz>>>
            and 20 others
    = note: required for `std::vec::Vec<f32>` to implement `std::convert::Into<clickhouse_rs::types::Value>`

I found #36 where you included an example but it uses Block::column(). Ok I tried to refactor my whole code to insert columns instead of rows, but now it breaks with this:

error[E0277]: the trait bound `chrono::DateTime<chrono::Utc>: clickhouse_rs::types::stat_buffer::StatBuffer` is not satisfied
   --> src/tasks/clickhouse_pusher.rs:287:28
    |
287 |         .column("created", created)
    |          ------            ^^^^^^^ the trait `clickhouse_rs::types::stat_buffer::StatBuffer` is not implemented for `chrono::DateTime<chrono::Utc>`
    |          |
    |          required by a bound introduced by this call
    |
    = help: the following other types implement trait `clickhouse_rs::types::stat_buffer::StatBuffer`:
              bool
              f32
              f64
              i16
              i32
              i64
              i8
              u16
            and 3 others
    = note: required for `std::vec::Vec<chrono::DateTime<chrono::Utc>>` to implement `clickhouse_rs::types::column::ColumnFrom`
note: required by a bound in `clickhouse_rs::Block::<K>::column`
   --> /Users/rogerio/.cargo/git/checkouts/clickhouse-rs-37da3cb97e01332d/123ec50/src/types/block/mod.rs:237:12
    |
237 |         S: ColumnFrom,
    |            ^^^^^^^^^^ required by this bound in `clickhouse_rs::Block::<K>::column`

I'm sorry to say and thanks for your work, but this is quite confusing. It seems each kind of data-inserting method has a different subset of supported types... With row! I can't insert Arrays of floats, and with .column() I can't insert dates. What would I do, please?

rsalmei avatar Jan 26 '23 15:01 rsalmei