Skip to content

Commit 4e90097

Browse files
authored
fix: add max_items to duckdb client (#229)
Closes #228
1 parent db3ff56 commit 4e90097

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

python/rustac/rustac.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class DuckdbClient:
9696
collections: str | list[str] | None = None,
9797
intersects: str | dict[str, Any] | None = None,
9898
limit: int | None = None,
99+
max_items: int | None = None,
99100
offset: int | None = None,
100101
bbox: list[float] | None = None,
101102
datetime: str | None = None,
@@ -116,6 +117,8 @@ class DuckdbClient:
116117
intersects: Searches items by performing intersection between their
117118
geometry and provided GeoJSON geometry.
118119
limit: The number of items to return.
120+
max_items: The number of items to return (included so that we have a
121+
similar call API to normal search)
119122
offset: The number of items to skip before returning.
120123
bbox: Requested bounding box.
121124
datetime: Single date+time, or a range (`/` separator), formatted to

src/duckdb.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,16 @@ impl DuckdbClient {
6161
Ok(count)
6262
}
6363

64-
#[pyo3(signature = (href, *, intersects=None, ids=None, collections=None, limit=None, bbox=None, datetime=None, include=None, exclude=None, sortby=None, filter=None, query=None, **kwargs))]
64+
#[pyo3(signature = (href, *, intersects=None, ids=None, collections=None, limit=None, max_items=None, bbox=None, datetime=None, include=None, exclude=None, sortby=None, filter=None, query=None, **kwargs))]
6565
fn search<'py>(
6666
&self,
6767
py: Python<'py>,
6868
href: String,
6969
intersects: Option<StringOrDict>,
7070
ids: Option<StringOrList>,
7171
collections: Option<StringOrList>,
72-
limit: Option<u64>,
72+
mut limit: Option<u64>,
73+
max_items: Option<u64>,
7374
bbox: Option<Vec<f64>>,
7475
datetime: Option<String>,
7576
include: Option<StringOrList>,
@@ -79,6 +80,12 @@ impl DuckdbClient {
7980
query: Option<Bound<'py, PyDict>>,
8081
kwargs: Option<Bound<'py, PyDict>>,
8182
) -> Result<Bound<'py, PyList>> {
83+
if max_items.is_some() {
84+
if limit.is_some() {
85+
tracing::warn!("Both max_items and limit are set, overriding limit with max_items");
86+
}
87+
limit = max_items;
88+
}
8289
let search = crate::search::build(
8390
intersects,
8491
ids,

tests/test_duckdb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,9 @@ def test_aws_credential_chain(client: DuckdbClient) -> None:
9595
def test_search_union_by_name(client: DuckdbClient) -> None:
9696
items = client.search("data/*.parquet")
9797
assert len(items) == 101
98+
99+
100+
def test_max_items_type(client: DuckdbClient) -> None:
101+
# https://github.com/stac-utils/rustac-py/issues/228
102+
items = client.search("data/*.parquet", max_items=1)
103+
assert len(items) == 1

0 commit comments

Comments
 (0)