Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust): adjust scan range to avoid unnecessary warnings #3248

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions python/python/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,11 @@ def test_limit_offset(tmp_path: Path, data_storage_version: str):

# test just limit
assert dataset.to_table(limit=10) == table.slice(0, 10)
assert dataset.to_table(limit=100) == table.slice(0, 100)

# test just offset
assert dataset.to_table(offset=10) == table.slice(10, 100)
assert dataset.to_table(offset=0) == table.slice(0, 100)
assert dataset.to_table(offset=10) == table.slice(10, 90)

# test both
assert dataset.to_table(offset=10, limit=10) == table.slice(10, 10)
Expand All @@ -503,7 +505,18 @@ def test_limit_offset(tmp_path: Path, data_storage_version: str):
assert dataset.to_table(offset=50, limit=25) == table.slice(50, 25)

# Limit past the end
assert dataset.to_table(offset=50, limit=100) == table.slice(50, 50)
assert dataset.to_table(limit=101) == table.slice(0, 100)

# Limit with offset past the end
assert dataset.to_table(offset=50, limit=51) == table.slice(50, 50)

# Offset past the end
assert dataset.to_table(offset=100) == table.slice(100, 0) # Empty table
assert dataset.to_table(offset=101) == table.slice(100, 0) # Empty table

# Offset with limit past the end
assert dataset.to_table(offset=100, limit=1) == table.slice(100, 0) # Empty table
assert dataset.to_table(offset=101, limit=1) == table.slice(100, 0) # Empty table

# Invalid limit / offset
with pytest.raises(ValueError, match="Offset must be non-negative"):
Expand Down
14 changes: 10 additions & 4 deletions rust/lance/src/dataset/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,12 +1219,18 @@ impl Scanner {
} else {
match (self.limit, self.offset) {
(None, None) => None,
(Some(limit), None) => Some(0..limit as u64),
(Some(limit), None) => {
let num_rows = self.dataset.count_all_rows().await? as i64;
Some(0..limit.min(num_rows) as u64)
}
(None, Some(offset)) => {
let num_rows = self.dataset.count_all_rows().await?;
Some(offset as u64..num_rows as u64)
let num_rows = self.dataset.count_all_rows().await? as i64;
Some(offset.min(num_rows) as u64..num_rows as u64)
}
(Some(limit), Some(offset)) => {
let num_rows = self.dataset.count_all_rows().await? as i64;
Some(offset.min(num_rows) as u64..(offset + limit).min(num_rows) as u64)
}
(Some(limit), Some(offset)) => Some(offset as u64..(offset + limit) as u64),
}
};
let mut use_limit_node = true;
Expand Down
Loading