Skip to content

Commit 42c8e3d

Browse files
authored
Fix Filestore unable to read sizes smaller than offset (#1907)
* Fix filestore unable to read sizes smaller than offset * add test for filestore using small buffer
1 parent 69d4ac7 commit 42c8e3d

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

tiledb/filestore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def read(self, offset: int = 0, size: int = -1) -> bytes:
6767

6868
if size == -1:
6969
size = len(self)
70-
size = max(size - offset, 0)
70+
size = min(size, len(self) - offset)
7171

7272
return lt.Filestore._buffer_export(
7373
self._ctx,

tiledb/tests/test_filestore.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,33 @@ def test_buffer(self, capfd):
3535
schema.attr(0).dump()
3636
assert_captured(capfd, "Type: BLOB")
3737

38-
data = b"buffer"
39-
4038
fs = tiledb.Filestore(path)
4139
fs.write(data)
4240
assert bytes(data) == fs.read()
4341

42+
def test_small_buffer(self, capfd):
43+
path = self.path("test_small_buffer")
44+
# create a 4 byte array
45+
data = b"abcd"
46+
47+
fs = tiledb.Filestore(path)
48+
49+
with self.assertRaises(tiledb.TileDBError):
50+
fs.write(data)
51+
52+
schema = tiledb.ArraySchema.from_file()
53+
tiledb.Array.create(path, schema)
54+
55+
assert schema.attr(0).name == "contents"
56+
assert schema.attr(0).dtype == np.bytes_
57+
58+
schema.attr(0).dump()
59+
assert_captured(capfd, "Type: BLOB")
60+
61+
fs = tiledb.Filestore(path)
62+
fs.write(data)
63+
assert data[3:4] == fs.read(offset=3, size=1)
64+
4465
def test_uri(self, text_fname):
4566
path = self.path("test_uri")
4667
schema = tiledb.ArraySchema.from_file(text_fname)

0 commit comments

Comments
 (0)