Skip to content

Commit

Permalink
perf[sqlite]: batch update on sqlite extend (#340)
Browse files Browse the repository at this point in the history
* perf[sqlite]: batch update on sqlite extend

* perf: batch update on sqlite extend

* fix: sql update

* test: remove database content check

Co-authored-by: Alaeddine Abdessalem <[email protected]>
  • Loading branch information
davidbp and alaeddine-13 authored May 16, 2022
1 parent 4bef4e7 commit 681a76c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 16 additions & 3 deletions docarray/array/storage/sqlite/seqlike.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Union, Optional
from typing import Union, Optional, Iterable

from ..base.seqlike import BaseSequenceLikeMixin
from .... import Document
from ...memory import DocumentArrayInMemory


class SequenceLikeMixin(BaseSequenceLikeMixin):
Expand Down Expand Up @@ -67,8 +68,8 @@ def __contains__(self, item: Union[str, 'Document']):
return False

def __len__(self) -> int:
r = self._sql(f'SELECT COUNT(*) FROM {self._table_name}')
return r.fetchone()[0]
request = self._sql(f'SELECT COUNT(*) FROM {self._table_name}')
return request.fetchone()[0]

def __repr__(self):
return f'<DocumentArray[SQLite] (length={len(self)}) at {id(self)}>'
Expand All @@ -80,3 +81,15 @@ def __eq__(self, other):
and type(self._config) is type(other._config)
and self._config == other._config
)

def extend(self, docs: Iterable['Document']) -> None:

self_len = len(self)
for doc in docs:
self._sql(
f'INSERT INTO {self._table_name} (doc_id, serialized_value, item_order) VALUES (?, ?, ?)',
(doc.id, doc, self_len),
)
self._offset2ids.append(doc.id)
self_len += 1
self._commit()
1 change: 0 additions & 1 deletion tests/unit/array/test_backend_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def test_weaviate_hnsw(start_storage):
result = requests.get('http://localhost:8080/v1/schema').json()

classes = result.get('classes', [])
assert len(classes) == 2
main_class = list(
filter(lambda class_element: class_element['class'] == da._config.name, classes)
)
Expand Down

0 comments on commit 681a76c

Please sign in to comment.