Skip to content

Commit 7a4c9c5

Browse files
committed
minor changes to write in chunkstore
1 parent 39fcb8f commit 7a4c9c5

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

arctic/chunkstore/chunkstore.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -192,31 +192,30 @@ def write(self, symbol, item, chunk_size):
192192
doc['dtype_metadata'] = dict(dtype.metadata or {})
193193
doc['len'] = len(item)
194194

195-
seg_count = 0
196-
197195
chunks = [r.tostring() for r in records]
198196
chunks = compress_array(chunks)
199197

198+
op = False
200199
bulk = self._collection.initialize_unordered_bulk_op()
201200
for chunk, rng in zip(chunks, ranges):
202201
start = rng[0]
203202
end = rng[1]
204-
seg_count += 1
205-
chunk = {'data': Binary(chunk), 'compressed': True}
203+
chunk = {'data': Binary(chunk)}
206204
chunk['start'] = start
207205
chunk['end'] = end
208206
chunk['symbol'] = symbol
209207
chunk['sha'] = checksum(symbol, chunk)
210208
if chunk['sha'] not in previous_shas:
209+
op = True
211210
bulk.find({'symbol': symbol, 'sha': chunk['sha']},
212211
).upsert().update_one({'$set': chunk})
213212
else:
214213
# already exists, dont need to update in mongo
215-
previous_shas = previous_shas.remove(chunk['sha'])
216-
if seg_count != 0:
214+
previous_shas.remove(chunk['sha'])
215+
if op:
217216
bulk.execute()
218217

219-
doc['chunk_count'] = seg_count
218+
doc['chunk_count'] = len(chunks)
220219
doc['append_size'] = 0
221220
doc['append_count'] = 0
222221

@@ -296,7 +295,7 @@ def append(self, symbol, item):
296295
start = rng[0]
297296
end = rng[-1]
298297

299-
segment = {'data': Binary(chunk), 'compressed': True}
298+
segment = {'data': Binary(chunk)}
300299
segment['start'] = start
301300
segment['end'] = end
302301
self._collection.update_one({'symbol': symbol, 'sha': checksum(symbol, segment)},
@@ -360,7 +359,7 @@ def update(self, symbol, item):
360359
sym['len'] += rec_len
361360
seg_count += 1
362361
seg_len += rec_len
363-
segment = {'data': Binary(chunk), 'compressed': True}
362+
segment = {'data': Binary(chunk)}
364363
segment['start'] = start
365364
segment['end'] = end
366365
sha = checksum(symbol, segment)

tests/integration/chunkstore/test_chunkstore.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def test_overwrite_dataframe(chunkstore_lib):
3030
)
3131

3232
dg = DataFrame(data={'data': [1, 2, 3]},
33-
index=MultiIndex.from_tuples([(dt(2015, 1, 1), 1),
34-
(dt(2015, 1, 2), 1),
35-
(dt(2015, 1, 3), 1)],
33+
index=MultiIndex.from_tuples([(dt(2016, 1, 1), 1),
34+
(dt(2016, 1, 2), 1),
35+
(dt(2016, 1, 3), 1)],
3636
names=['date', 'id'])
3737
)
3838
chunkstore_lib.write('test_df', df, 'D')

0 commit comments

Comments
 (0)