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

Add code to properly extract tags from the incoming point in BoostSupport.cxx #113

Closed
ItsGarand opened this issue Mar 14, 2022 · 4 comments
Assignees
Milestone

Comments

@ItsGarand
Copy link

ItsGarand commented Mar 14, 2022

In BoostSupport.cxx queryImpl(), the response to the query (const auto response = transport->query(querty);) returns a JSON string and then loaded into a ptree.
so, all field data is represented as a string in the ptree.

The decision was made to make all strings found in fields into tags. The original tags if any are marked as such in the incoming data so they should be preserved that way in the reconstructed point. String data in fields are still fields and should not be added as tags.

so.....

at line 58 insert:

Point point{series.second.getstd::string("name", "")};
// add the tags if they exist
for (auto &tag : series.second.get_child("tags"))
{
std::string tagName = tag.first;
std::string tagValue = tag.second.data();
point.addTag(tagName, tagValue);
}
// add the field data

When adding fileds, don't assume a double - Influx is flexible - data could be int or float or string as well. The code could try to determine the type by doing some range/format checking(int/long/float/double/string) and doing the conversion here. I would suggest leaving it as a string representation and letting the user do the required conversion.
Change line 76 from:
point.addField(column, boost::lexical_cast(value));
to:
point.addField(column, value); *** See ticket 115

Don't assume string data is automatically a tag.
Remove line 80: point.addTag(column, value);
in it's place add a warning to cout saying field could not be added:
std::cout << Error adding field to point - Column: " << column << " Value: " << value << std::endl;

@offa
Copy link
Owner

offa commented Mar 14, 2022

Indeed, the json query handling needs some improvements.

The original tags if any are marked as such in the incoming data so they should be preserved that way in the reconstructed point.

Is this 2.x (1.x doesn't contain any tags in the response json)?

I would suggest leaving it as a string representation and letting the user do the required conversion.

Good point, this might be the safest way.

@ItsGarand
Copy link
Author

ItsGarand commented Mar 15, 2022

I am using Influxdb 1.7.10. If your query contains a GROUP BY clause and you use your tags, the output JSON will contain a tags structure

So, if you have a set of points like:
time, TAG1="A", TAG2="B", DEV_NUM="1" number1=10, number2=20, number3=30

query = SELECT number1, number2 FROM my_measurement WHERE DEV_NUM=1 GROUP BY TAG1, TAG2, DEV_NUM

The response JSON will look like:
{"result":[{statement_id=0, "series":[{"name":"results", "tags":{"TAG1":"A", "TAG2":"B", DEV_NUM="1"}, "columns": ["time", "number1", "number2"], "values": [...]}]}]}

@offa
Copy link
Owner

offa commented Mar 15, 2022

Thanks, group by was the missing hint.

In cases where there's already a tags element it makes sense to use it. I'll have a look at it. 👍

@offa offa self-assigned this Mar 15, 2022
@offa offa added this to the v0.7.0 milestone Mar 15, 2022
@offa
Copy link
Owner

offa commented Mar 17, 2022

Merged.

@offa offa closed this as completed Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants