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

Some tags are converted to fields

Open Globostofo opened this issue 6 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