Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quotation marks of tag values and escaping of field values #68

Conversation

Robert-Steiner
Copy link
Contributor

Description

Fixes two issues related to quotation marks of tag values and improper escaping of field values.

  1. Removed additional quotation marks for tag values with the type Float, SignedInteger and UnsignedInteger, otherwise they will be part of the string. (Removing the quotation marks for Text was already fixed in Fix improper quoting on tag values when the value was text #64.)

InfluxDB docs:

Do not double or single quote measurement names, tag keys, tag values, and field keys. It is valid line protocol but InfluxDB assumes that the quotes are part of the name.

  1. Removed escaping of commas, equals and spaces for field values.

InfluxDB docs:

For string field values use a backslash character \ to escape:
double quotes "

Checklist

  • Formatted code using cargo fmt --all
  • Linted code using clippy cargo clippy --all-targets --all-features -- -D warnings
  • Updated README.md using cargo readme -r influxdb -t ../README.tpl > README.md
  • Reviewed the diff. Did you leave any print statements or unnecessary comments?
  • Any unfinished work that warrants a separate issue captured in an issue with a TODO code comment

@Empty2k12 Empty2k12 merged commit 55d497f into influxdb-rs:master Sep 1, 2020
@Empty2k12
Copy link
Collaborator

Thanks for opening this PR 👍

Hopefully all issues regarding the line-protocol are resolved now!

If you notice any other problems feel free to open more issues or pull requests.

@mcronce
Copy link
Contributor

mcronce commented Sep 29, 2020

@Empty2k12 this and #64 should actually fix a problem I was just debugging :) what are the chances you could push a new release to crates.io that includes these?

@Empty2k12
Copy link
Collaborator

@mcronce I'm looking to get #69 reviewed, and then release the crate on crates. Until then, you can reference the Git repo directly.

@mcronce
Copy link
Contributor

mcronce commented Oct 1, 2020

@Empty2k12 So, this is fairly weird - I gave that a shot and got the following pair of errors (with a bonus warning) that, all together, are super confusing:

error[E0277]: the trait bound `influxdb::WriteQuery: influxdb::query::Query` is not satisfied
  --> src/main.rs:84:23
   |
84 |             match client.query(&query).await {
   |                                ^^^^^^ the trait `influxdb::query::Query` is not implemented for `influxdb::WriteQuery`

error[E0277]: the trait bound `influxdb::query::QueryTypes<'_>: From<&influxdb::WriteQuery>` is not satisfied
  --> src/main.rs:84:17
   |
84 |             match client.query(&query).await {
   |                          ^^^^^ the trait `From<&influxdb::WriteQuery>` is not implemented for `influxdb::query::QueryTypes<'_>`
   |
   = help: the following implementations were found:
             <influxdb::query::QueryTypes<'a> as From<&'a influxdb::query::read_query::ReadQuery>>
             <influxdb::query::QueryTypes<'a> as From<&'a influxdb::query::write_query::WriteQuery>>
   = note: required because of the requirements on the impl of `Into<influxdb::query::QueryTypes<'_>>` for `&influxdb::WriteQuery`

warning: unused import: `influxdb::Query`
  --> src/main.rs:19:5
   |
19 | use influxdb::Query;
   |     ^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

But it gets weirder. This doesn't happen when I specify version 0.1 from crates.io, but it does happen when I clone the repo, checkout the 0.1.0 tag, and build against that. I thought maybe I was hitting a compiler bug, but I tried updating stable and nightly to latest and got the same result.

This is probably just a fundamental language misunderstanding on my part, but what are the chances you have a recommendation? Also, if it's easier/preferable, I can file a separate issue.

In any case, the code in question:

// queries is a Vec<WriteQuery>
for query in queries.into_iter() {
        match client.query(&query).await {
                Ok(_) => (),
                Err(e) => println!("Query for character {} fail: {:?}", id, e)
        };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants