Skip to content

Commit 6953f09

Browse files
committed
Merge pull request influxdata#20 from manugarri/master
Added batch option for write_points
2 parents f4d9c5a + 4593832 commit 6953f09

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

influxdb/client.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,37 @@ def switch_user(self, username, password):
6262
def write_points(self, *args, **kwargs):
6363
"""
6464
Write to multiple time series names
65-
"""
65+
66+
Parameters
67+
----------
68+
batch_size : Optional. Int value to write the points in batches instead
69+
of all at one time.
70+
Useful for when doing data dumps from one database to another or
71+
when doing a massive write operation
72+
"""
73+
74+
def list_chunks(l, n):
75+
""" Yield successive n-sized chunks from l.
76+
"""
77+
for i in xrange(0, len(l), n):
78+
yield l[i:i+n]
79+
80+
batch_size = kwargs.get('batch_size')
81+
if batch_size:
82+
for data in kwargs.get('data'):
83+
name = data.get('name')
84+
columns = data.get('columns')
85+
point_list = data.get('points')
86+
total_batches = len(point_list) * 1.0/batch_size
87+
for batch in list_chunks(point_list, batch_size):
88+
data = [{"points": batch,
89+
"name": name,
90+
"columns": columns}]
91+
time_precision = kwargs.get('time_precision', 's')
92+
self.write_points_with_precision(data=data,
93+
time_precision=time_precision)
94+
return True
95+
6696
return self.write_points_with_precision(*args, **kwargs)
6797

6898
def write_points_with_precision(self, data, time_precision='s'):

0 commit comments

Comments
 (0)