Skip to content

Commit

Permalink
Fix Filestore unable to read sizes smaller than offset (#1907)
Browse files Browse the repository at this point in the history
* Fix filestore unable to read sizes smaller than offset
* add test for filestore using small buffer
  • Loading branch information
kounelisagis authored Mar 1, 2024
1 parent 69d4ac7 commit 42c8e3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tiledb/filestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def read(self, offset: int = 0, size: int = -1) -> bytes:

if size == -1:
size = len(self)
size = max(size - offset, 0)
size = min(size, len(self) - offset)

return lt.Filestore._buffer_export(
self._ctx,
Expand Down
25 changes: 23 additions & 2 deletions tiledb/tests/test_filestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,33 @@ def test_buffer(self, capfd):
schema.attr(0).dump()
assert_captured(capfd, "Type: BLOB")

data = b"buffer"

fs = tiledb.Filestore(path)
fs.write(data)
assert bytes(data) == fs.read()

def test_small_buffer(self, capfd):
path = self.path("test_small_buffer")
# create a 4 byte array
data = b"abcd"

fs = tiledb.Filestore(path)

with self.assertRaises(tiledb.TileDBError):
fs.write(data)

schema = tiledb.ArraySchema.from_file()
tiledb.Array.create(path, schema)

assert schema.attr(0).name == "contents"
assert schema.attr(0).dtype == np.bytes_

schema.attr(0).dump()
assert_captured(capfd, "Type: BLOB")

fs = tiledb.Filestore(path)
fs.write(data)
assert data[3:4] == fs.read(offset=3, size=1)

def test_uri(self, text_fname):
path = self.path("test_uri")
schema = tiledb.ArraySchema.from_file(text_fname)
Expand Down

0 comments on commit 42c8e3d

Please sign in to comment.