Skip to content

Commit 0bb9a05

Browse files
authoredMar 20, 2020
Add getTags to Point clas (awegrzyn#60)
1 parent 7ddf338 commit 0bb9a05

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed
 

‎include/Point.h

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class Point
4646
/// Fields getter
4747
std::string getFields() const;
4848

49+
/// Tags getter
50+
std::string getTags() const;
51+
4952
protected:
5053
/// A value
5154
std::variant<long long int, std::string, double> mValue;

‎src/InfluxDB.cxx

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ std::vector<Point> InfluxDB::query(const std::string& query)
108108
point.setTimestamp(std::chrono::system_clock::from_time_t(std::mktime(&tm)));
109109
continue;
110110
}
111+
// cast all values to double, if strings add to tags
111112
try { point.addField(column, boost::lexical_cast<double>(value)); }
112113
catch(...) { point.addTag(column, value); }
113114
}

‎src/Point.cxx

+5
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ std::string Point::getFields() const
8181
return mFields;
8282
}
8383

84+
std::string Point::getTags() const
85+
{
86+
return mTags.substr(1, mTags.size());
87+
}
88+
8489
} // namespace influxdb

‎test/testQuery.cxx

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ BOOST_AUTO_TEST_CASE(query1)
2020
BOOST_CHECK_EQUAL(points[0].getFields(), "value=10");
2121
BOOST_CHECK_EQUAL(points[1].getFields(), "value=20");
2222
BOOST_CHECK_EQUAL(points[2].getFields(), "value=200");
23+
BOOST_CHECK_EQUAL(points[0].getTags(), "host=localhost");
24+
BOOST_CHECK_EQUAL(points[1].getTags(), "host=localhost");
25+
BOOST_CHECK_EQUAL(points[2].getTags(), "host=localhost");
2326
}
2427

2528
BOOST_AUTO_TEST_CASE(failedQuery1)

0 commit comments

Comments
 (0)