Skip to content

Commit

Permalink
fix: update cursor correctly in blob file API (#3018)
Browse files Browse the repository at this point in the history
When `read` returns it should update the cursor to the end of the data
just read. However, we were calculating this as `end` and not `end -
position`.

The cursor is supposed to be relative to the start of the blob in the
file (e.g. 0 == `position`).
  • Loading branch information
westonpace authored Oct 18, 2024
1 parent 7373189 commit f9024ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions python/python/tests/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ def test_blob_file_seek(tmp_path, dataset_with_blobs):
assert f.read(1) == b"a"


def test_blob_file_read_middle(tmp_path, dataset_with_blobs):
# This regresses an issue where we were not setting the cursor
# correctly after a call to `read` when the blob was not the
# first thing in the file.
row_ids = (
dataset_with_blobs.to_table(columns=[], with_row_id=True)
.column("_rowid")
.to_pylist()
)
blobs = dataset_with_blobs.take_blobs(row_ids, "blobs")
with blobs[1] as f:
assert f.read(1) == b"b"
assert f.read(1) == b"a"
assert f.read(1) == b"r"


def test_take_deleted_blob(tmp_path, dataset_with_blobs):
row_ids = (
dataset_with_blobs.to_table(columns=[], with_row_id=True)
Expand Down
6 changes: 3 additions & 3 deletions rust/lance/src/dataset/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ impl BlobFile {
let size = self.size;
self.do_with_reader(|cursor, reader| async move {
let start = position as usize + cursor as usize;
let size = len.min((size - cursor) as usize);
let end = start + size;
let read_size = len.min((size - cursor) as usize);
let end = start + read_size;
let data = reader.get_range(start..end).await?;
Ok((end as u64, data))
Ok((end as u64 - position, data))
})
.await
}
Expand Down

0 comments on commit f9024ce

Please sign in to comment.