Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Add getTags to Point clas (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
awegrzyn authored Mar 20, 2020
1 parent 7ddf338 commit 0bb9a05
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class Point
/// Fields getter
std::string getFields() const;

/// Tags getter
std::string getTags() const;

protected:
/// A value
std::variant<long long int, std::string, double> mValue;
Expand Down
1 change: 1 addition & 0 deletions src/InfluxDB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ std::vector<Point> 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<double>(value)); }
catch(...) { point.addTag(column, value); }
}
Expand Down
5 changes: 5 additions & 0 deletions src/Point.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ std::string Point::getFields() const
return mFields;
}

std::string Point::getTags() const
{
return mTags.substr(1, mTags.size());
}

} // namespace influxdb
3 changes: 3 additions & 0 deletions test/testQuery.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0bb9a05

Please sign in to comment.