From 743e4c961521b58f085e2167ac554c8aee7445bb Mon Sep 17 00:00:00 2001 From: Alexander Mancevice Date: Tue, 2 Feb 2016 16:08:52 -0500 Subject: [PATCH 1/3] Allow multiple statements in single query Allows users to pass in multiple ;-separated queries into the same call. Returns a list of ResultSet instances, as if the query() method had been mapped across the different queries. ```python client.query("SELECT * FROM mymeas WHERE time>now()-1h; " \ "SELECT * FROM othermeas WHERE time>now-1h") ``` --- influxdb/_dataframe_client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/influxdb/_dataframe_client.py b/influxdb/_dataframe_client.py index deae1beb..73a01745 100644 --- a/influxdb/_dataframe_client.py +++ b/influxdb/_dataframe_client.py @@ -101,6 +101,8 @@ def get_list_series(self, database=None): def _to_dataframe(self, rs): result = {} + if isinstance(rs, list): + return map(self._to_dataframe, rs) for key, data in rs.items(): name, tags = key if tags is None: From e0384b9b15a66ead55b426f2512b6b1f26b4e30d Mon Sep 17 00:00:00 2001 From: Alexander Mancevice Date: Thu, 4 Feb 2016 15:12:10 -0500 Subject: [PATCH 2/3] Added test for multiple statements per query --- influxdb/tests/dataframe_client_test.py | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/influxdb/tests/dataframe_client_test.py b/influxdb/tests/dataframe_client_test.py index 07998803..f76ca498 100644 --- a/influxdb/tests/dataframe_client_test.py +++ b/influxdb/tests/dataframe_client_test.py @@ -244,6 +244,56 @@ def test_query_into_dataframe(self): for k in expected: assert_frame_equal(expected[k], result[k]) + def test_multiquery_into_dataframe(self): + data = { + "results": [ + { + "series": [ + { + "name": "cpu_load_short", + "columns": ["time","value"], + "values": [ + ["2015-01-29T21:55:43.702900257Z", 0.55], + ["2015-01-29T21:55:43.702900257Z", 23422], + ["2015-06-11T20:46:02Z", 0.64] + ] + } + ] + }, { + "series": [ + { + "name": "cpu_load_short", + "columns": ["time","count"], + "values": [ + ["1970-01-01T00:00:00Z", 3] + ] + } + ] + } + ] + } + + pd1 = pd.DataFrame( + [[0.55], [23422.0], [0.64]], columns=['value'], + index=pd.to_datetime([ + "2015-01-29 21:55:43.702900257+0000", + "2015-01-29 21:55:43.702900257+0000", + "2015-06-11 20:46:02+0000"])).tz_localize('UTC') + pd2 = pd.DataFrame( + [[3]], columns=['count'], + index=pd.to_datetime(["1970-01-01 00:00:00+00:00"])).tz_localize('UTC') + expected = [{'cpu_load_short':pd1}, {'cpu_load_short':pd2}] + + + cli = DataFrameClient('host', 8086, 'username', 'password', 'db') + with _mocked_session(cli, 'GET', 200, data): + result = cli.query( + "SELECT value FROM cpu_load_short WHERE region='us-west';"\ + "SELECT count(value) FROM cpu_load_short WHERE region='us-west'") + for r,e in zip(result, expected): + for k in e: + assert_frame_equal(e[k], r[k]) + def test_query_with_empty_result(self): cli = DataFrameClient('host', 8086, 'username', 'password', 'db') with _mocked_session(cli, 'GET', 200, {"results": [{}]}): From 66169efcff04b24f94f9c39623ad1fb448e076e2 Mon Sep 17 00:00:00 2001 From: Alexander Mancevice Date: Thu, 4 Feb 2016 15:50:12 -0500 Subject: [PATCH 3/3] flake8 fixes --- influxdb/tests/dataframe_client_test.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/influxdb/tests/dataframe_client_test.py b/influxdb/tests/dataframe_client_test.py index f76ca498..721d1aeb 100644 --- a/influxdb/tests/dataframe_client_test.py +++ b/influxdb/tests/dataframe_client_test.py @@ -251,7 +251,7 @@ def test_multiquery_into_dataframe(self): "series": [ { "name": "cpu_load_short", - "columns": ["time","value"], + "columns": ["time", "value"], "values": [ ["2015-01-29T21:55:43.702900257Z", 0.55], ["2015-01-29T21:55:43.702900257Z", 23422], @@ -263,7 +263,7 @@ def test_multiquery_into_dataframe(self): "series": [ { "name": "cpu_load_short", - "columns": ["time","count"], + "columns": ["time", "count"], "values": [ ["1970-01-01T00:00:00Z", 3] ] @@ -281,16 +281,16 @@ def test_multiquery_into_dataframe(self): "2015-06-11 20:46:02+0000"])).tz_localize('UTC') pd2 = pd.DataFrame( [[3]], columns=['count'], - index=pd.to_datetime(["1970-01-01 00:00:00+00:00"])).tz_localize('UTC') - expected = [{'cpu_load_short':pd1}, {'cpu_load_short':pd2}] - + index=pd.to_datetime(["1970-01-01 00:00:00+00:00"]))\ + .tz_localize('UTC') + expected = [{'cpu_load_short': pd1}, {'cpu_load_short': pd2}] cli = DataFrameClient('host', 8086, 'username', 'password', 'db') + iql = "SELECT value FROM cpu_load_short WHERE region='us-west';"\ + "SELECT count(value) FROM cpu_load_short WHERE region='us-west'" with _mocked_session(cli, 'GET', 200, data): - result = cli.query( - "SELECT value FROM cpu_load_short WHERE region='us-west';"\ - "SELECT count(value) FROM cpu_load_short WHERE region='us-west'") - for r,e in zip(result, expected): + result = cli.query(iql) + for r, e in zip(result, expected): for k in e: assert_frame_equal(e[k], r[k]) 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