diff --git a/include/Point.h b/include/Point.h index cce15f55..d36db9ea 100644 --- a/include/Point.h +++ b/include/Point.h @@ -46,6 +46,9 @@ class Point /// Fields getter std::string getFields() const; + /// Tags getter + std::string getTags() const; + protected: /// A value std::variant mValue; diff --git a/src/InfluxDB.cxx b/src/InfluxDB.cxx index 0e46fbfe..f760b8e5 100644 --- a/src/InfluxDB.cxx +++ b/src/InfluxDB.cxx @@ -108,6 +108,7 @@ std::vector InfluxDB::query(const std::string& query) point.setTimestamp(std::chrono::system_clock::from_time_t(std::mktime(&tm))); continue; } + // cast all values to double, if strings add to tags try { point.addField(column, boost::lexical_cast(value)); } catch(...) { point.addTag(column, value); } } diff --git a/src/Point.cxx b/src/Point.cxx index 3263f116..cc64f49a 100644 --- a/src/Point.cxx +++ b/src/Point.cxx @@ -81,4 +81,9 @@ std::string Point::getFields() const return mFields; } +std::string Point::getTags() const +{ + return mTags.substr(1, mTags.size()); +} + } // namespace influxdb diff --git a/test/testQuery.cxx b/test/testQuery.cxx index bdea2bc8..aac6fad7 100644 --- a/test/testQuery.cxx +++ b/test/testQuery.cxx @@ -20,6 +20,9 @@ BOOST_AUTO_TEST_CASE(query1) BOOST_CHECK_EQUAL(points[0].getFields(), "value=10"); BOOST_CHECK_EQUAL(points[1].getFields(), "value=20"); BOOST_CHECK_EQUAL(points[2].getFields(), "value=200"); + BOOST_CHECK_EQUAL(points[0].getTags(), "host=localhost"); + BOOST_CHECK_EQUAL(points[1].getTags(), "host=localhost"); + BOOST_CHECK_EQUAL(points[2].getTags(), "host=localhost"); } BOOST_AUTO_TEST_CASE(failedQuery1)