Skip to content

Commit 1e8e3dd

Browse files
committed
Merge pull request influxdata#292 from amancevice/master
Allow multiple statements in single query
2 parents e242c30 + 66169ef commit 1e8e3dd

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

influxdb/_dataframe_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def get_list_series(self, database=None):
101101

102102
def _to_dataframe(self, rs):
103103
result = {}
104+
if isinstance(rs, list):
105+
return map(self._to_dataframe, rs)
104106
for key, data in rs.items():
105107
name, tags = key
106108
if tags is None:

influxdb/tests/dataframe_client_test.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,56 @@ def test_query_into_dataframe(self):
244244
for k in expected:
245245
assert_frame_equal(expected[k], result[k])
246246

247+
def test_multiquery_into_dataframe(self):
248+
data = {
249+
"results": [
250+
{
251+
"series": [
252+
{
253+
"name": "cpu_load_short",
254+
"columns": ["time", "value"],
255+
"values": [
256+
["2015-01-29T21:55:43.702900257Z", 0.55],
257+
["2015-01-29T21:55:43.702900257Z", 23422],
258+
["2015-06-11T20:46:02Z", 0.64]
259+
]
260+
}
261+
]
262+
}, {
263+
"series": [
264+
{
265+
"name": "cpu_load_short",
266+
"columns": ["time", "count"],
267+
"values": [
268+
["1970-01-01T00:00:00Z", 3]
269+
]
270+
}
271+
]
272+
}
273+
]
274+
}
275+
276+
pd1 = pd.DataFrame(
277+
[[0.55], [23422.0], [0.64]], columns=['value'],
278+
index=pd.to_datetime([
279+
"2015-01-29 21:55:43.702900257+0000",
280+
"2015-01-29 21:55:43.702900257+0000",
281+
"2015-06-11 20:46:02+0000"])).tz_localize('UTC')
282+
pd2 = pd.DataFrame(
283+
[[3]], columns=['count'],
284+
index=pd.to_datetime(["1970-01-01 00:00:00+00:00"]))\
285+
.tz_localize('UTC')
286+
expected = [{'cpu_load_short': pd1}, {'cpu_load_short': pd2}]
287+
288+
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
289+
iql = "SELECT value FROM cpu_load_short WHERE region='us-west';"\
290+
"SELECT count(value) FROM cpu_load_short WHERE region='us-west'"
291+
with _mocked_session(cli, 'GET', 200, data):
292+
result = cli.query(iql)
293+
for r, e in zip(result, expected):
294+
for k in e:
295+
assert_frame_equal(e[k], r[k])
296+
247297
def test_query_with_empty_result(self):
248298
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
249299
with _mocked_session(cli, 'GET', 200, {"results": [{}]}):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy