|
| 1 | +import random |
| 2 | + |
1 | 3 | import httpretty
|
| 4 | +import rx |
2 | 5 | from pandas import DataFrame
|
3 | 6 | from pandas._libs.tslibs.timestamps import Timestamp
|
| 7 | +from rx import operators as ops |
4 | 8 |
|
5 |
| -from influxdb_client import InfluxDBClient |
6 |
| -from tests.base_test import BaseTest |
| 9 | +from influxdb_client import InfluxDBClient, Point, WritePrecision, WriteOptions |
| 10 | +from tests.base_test import BaseTest, current_milli_time |
7 | 11 |
|
8 | 12 |
|
9 | 13 | class QueryDataFrameApi(BaseTest):
|
@@ -250,3 +254,37 @@ def test_more_table_custom_index(self):
|
250 | 254 | Timestamp('2019-11-12 08:09:07+0000'), Timestamp('2019-11-12 08:09:08+0000'),
|
251 | 255 | Timestamp('2019-11-12 08:09:09+0000')], list(_dataFrames[2].index))
|
252 | 256 | self.assertEqual(5, len(_dataFrames[2]))
|
| 257 | + |
| 258 | + |
| 259 | +class QueryDataFrameIntegrationApi(BaseTest): |
| 260 | + |
| 261 | + def test_large_amount_of_data(self): |
| 262 | + _measurement_name = "data_frame_" + str(current_milli_time()) |
| 263 | + |
| 264 | + def _create_point(index) -> Point: |
| 265 | + return Point(_measurement_name) \ |
| 266 | + .tag("deviceType", str(random.choice(['A', 'B']))) \ |
| 267 | + .tag("name", random.choice(['A', 'B'])) \ |
| 268 | + .field("uuid", random.randint(0, 10_000)) \ |
| 269 | + .field("co2", random.randint(0, 10_000)) \ |
| 270 | + .field("humid", random.randint(0, 10_000)) \ |
| 271 | + .field("lux", random.randint(0, 10_000)) \ |
| 272 | + .field("water", random.randint(0, 10_000)) \ |
| 273 | + .field("shine", random.randint(0, 10_000)) \ |
| 274 | + .field("temp", random.randint(0, 10_000)) \ |
| 275 | + .field("voc", random.randint(0, 10_000)) \ |
| 276 | + .time(time=(1583828781 + index), write_precision=WritePrecision.S) |
| 277 | + |
| 278 | + data = rx.range(0, 2_000).pipe(ops.map(lambda index: _create_point(index))) |
| 279 | + |
| 280 | + write_api = self.client.write_api(write_options=WriteOptions(batch_size=500)) |
| 281 | + write_api.write(org="my-org", bucket="my-bucket", record=data, write_precision=WritePrecision.S) |
| 282 | + write_api.__del__() |
| 283 | + |
| 284 | + query = 'from(bucket: "my-bucket")' \ |
| 285 | + '|> range(start: 2020-02-19T23:30:00Z, stop: now())' \ |
| 286 | + f'|> filter(fn: (r) => r._measurement == "{_measurement_name}")' |
| 287 | + |
| 288 | + result = self.client.query_api().query_data_frame(org="my-org", query=query) |
| 289 | + |
| 290 | + self.assertGreater(len(result), 1) |
0 commit comments