|
2 | 2 | import unittest |
3 | 3 | from unittest.mock import Mock |
4 | 4 |
|
5 | | -from influxdb_client_3 import PointSettings, InfluxDBClient3 |
| 5 | +from influxdb_client_3 import PointSettings, InfluxDBClient3, write_client_options, WriteOptions |
6 | 6 | from influxdb_client_3.write_client import WriteService |
7 | 7 | from influxdb_client_3.write_client.client.write.polars_dataframe_serializer import polars_data_frame_to_list_of_points |
8 | 8 |
|
@@ -61,3 +61,31 @@ def test_write_polars(self): |
61 | 61 | actual = self.client._write_api._write_service.post_write.call_args[1]['body'] |
62 | 62 | self.assertEqual(b'measurement temperature=22.4 1722470400000000000\n' |
63 | 63 | b'measurement temperature=21.8 1722474000000000000', actual) |
| 64 | + |
| 65 | + def test_write_polars_batching(self): |
| 66 | + import polars as pl |
| 67 | + df = pl.DataFrame({ |
| 68 | + "time": pl.Series(["2024-08-01 00:00:00", "2024-08-01 01:00:00"]).str.to_datetime(time_unit='ns'), |
| 69 | + "temperature": [22.4, 21.8], |
| 70 | + }) |
| 71 | + self.client = InfluxDBClient3( |
| 72 | + host="localhost", |
| 73 | + org="my_org", |
| 74 | + database="my_db", |
| 75 | + token="my_token", write_client_options=write_client_options( |
| 76 | + write_options=WriteOptions(batch_size=2) |
| 77 | + ) |
| 78 | + ) |
| 79 | + self.client._write_api._write_options = WriteOptions(batch_size=2) |
| 80 | + self.client._write_api._write_service = Mock(spec=WriteService) |
| 81 | + |
| 82 | + self.client.write( |
| 83 | + database="database", |
| 84 | + record=df, |
| 85 | + data_frame_measurement_name="measurement", |
| 86 | + data_frame_timestamp_column="time", |
| 87 | + ) |
| 88 | + |
| 89 | + actual = self.client._write_api._write_service.post_write.call_args[1]['body'] |
| 90 | + self.assertEqual(b'measurement temperature=22.4 1722470400000000000\n' |
| 91 | + b'measurement temperature=21.8 1722474000000000000', actual) |
0 commit comments