influxdb-cxx icon indicating copy to clipboard operation
influxdb-cxx copied to clipboard

Some tags are converted to fields

Open Globostofo opened this issue 10 months ago • 3 comments

I had a similar problem with issue #260.

When I query a point with a string Tag containing a numerical value (e.g "005"), the string is cast in double and added to Fields list instead of Tags. From what I've seen, this is due to this function.

As you mentioned here, we cannot tell if a string is a Field or a Tag in the JSON response. However, we can tell if a double is a Field or a Tag because double Fields don't have double quotes "" around them in the JSON response (while the tags are double quoted).

I created this simple test case to describe the problem :

auto db = InfluxDBFactory::Get("http://localhost:8086?db=TEST");

Point p = Point{ "test" }
              .addField("MyValue", 10)
              .addTag("MyStringTag", "hellothere")
              .addTag("MyIntTag", "005");
cout << "Original point" << endl
     << "Fields : " << p.getFields() << endl
     << "Tags   : " << p.getTags() << endl;
db->write(move(p));

for (const Point point : db->query("SELECT * FROM test"))
{
    cout << "===============" << endl
         << "After insertion and query" << endl
         << "Fields : " << point.getFields() << endl
         << "Tags   : " << point.getTags() << endl;
}

Here is the output :

Original point
Fields : MyValue=10i
Tags   : MyStringTag=hellothere,MyIntTag=005
===============
After insertion and query
Fields : MyIntTag=5.000000000000000000,MyValue=10.000000000000000000
Tags   : MyStringTag=hellothere

And here is the JSON response :

{"results":[{"statement_id":0,"series":[{"name":"test","columns":["time","MyIntTag","MyStringTag","MyValue"],"values":[["2025-06-21T18:30:57.29364337Z","005","hellothere",10]]}]}]}

We can see in the "values" field of the JSON that the Tag "005" is double quoted while the Field 10 isn't.

Is it possible to detect whether the field is a string (i.e has double quotes) before trying to cast it?

Thank you for your consideration :^) (btw I'm using InfluxDB 1.11.8 and influxdb-cxx 0.7.4)

Globostofo avatar Jun 21 '25 18:06 Globostofo

Since the value type has already be known at compile time it's more complicated I guess. value has no " anymore at this point.

I can't find a raw access to the value in the Boost Property Tree API docs. So the only option would be to call get_value<double>() and if it throws an exception it's likely a string and thus try again with get_value<std::string>()!? 😅

Btw. I'm not sure if there's even a way to determine tag or field. While the DB knows it, the response contains no information about it – there are just values. This code seems rather useless at this point. Is 'doubles are fields and strings are tags' only a guess?

offa avatar Jun 22 '25 15:06 offa

This code seems rather useless at this point.

Agree on this.

I also agree that the database doesn't provide enough information about this in the response json. I wonder how other client libraries manage to retrieve this data without confusing Fields and Tags.

I'll take a look tomorrow and I'll let you know if I find anything.

Globostofo avatar Jun 22 '25 16:06 Globostofo

I haven't looked at the details yet, but it looks like the Java API only sets fields and doesn't set any tags.

This code seems rather useless at this point.

Agree on this.

Some third party examples occasionally mention tags, but there's no real documentation which confirms it's existence.

Update

It seems tags is only used on GROUP BY, not document though.

offa avatar Jun 23 '25 17:06 offa