suharev7 / clickhouse-rs

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

Cannot use row! macro with columns that have a dot in their name #140

Closed rubik closed 3 years ago

rubik commented 3 years ago

First of all thank you so much for this library, it's extremely useful.

I came across the problem of inserting values for a column that has a dot in its name. This happens naturally with Nested fields. E.g.

let mut b = Block::new();
b.push(row! {
  meta.key: ev.key_name,
});

throws the following errors upon compilation:

error: casts cannot be followed by a field access
  --> src/store.rs:51:9
   |
51 |         meta.key: ev.key_name,
   |         ^^^^^^^^^^^^
   |
help: try surrounding the expression in parentheses
   |
51 |         (meta.key: ev).key_name,
   |         ^            ^

error: no rules expected the token `,`
  --> src/store.rs:51:30
   |
51 |         meta.key: ev.key_name,
   |                              ^ no rules expected this token in macro call

error: aborting due to 2 previous errors

I also tried wrapping the column name in double quotes, to no avail.

Can the macro be updated to allow such names?

suharev7 commented 3 years ago

You could rewrite it as:

b.push(row! {
    "meta.key" => ev.key_name,
});
rubik commented 3 years ago

@suharev7 Splendid, it works properly. I didn't understand from the macro code that it was an option; I have limited experience with macros. Should an example be added to the documentation, what do you think? I can open a PR for that.

suharev7 commented 3 years ago

That would be great if you make a PR with an example.

rubik commented 3 years ago

@suharev7 Done! #142