Skip to content

Commit

Permalink
feat(duckdb): add offset (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski authored Jan 3, 2025
1 parent 35bfcd7 commit c34baca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/duckdb/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- Offset ([#592](https://github.com/stac-utils/stac-rs/pull/592))

## [0.1.0] - 2025-01-02

### Changed
Expand Down
24 changes: 24 additions & 0 deletions crates/duckdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ impl Client {
let mut search: Search = search.into();
// Get suffix information early so we can take ownership of other parts of search as we go along.
let limit = search.items.limit.take();
let offset = search
.items
.additional_fields
.get("offset")
.and_then(|v| v.as_i64());
let sortby = std::mem::take(&mut search.items.sortby);
let fields = std::mem::take(&mut search.items.fields);

Expand Down Expand Up @@ -244,6 +249,9 @@ impl Client {
if let Some(limit) = limit {
suffix.push_str(&format!(" LIMIT {}", limit));
}
if let Some(offset) = offset {
suffix.push_str(&format!(" OFFSET {}", offset));
}
Ok(Query {
sql: format!(
"SELECT {} FROM read_parquet('{}'){}",
Expand Down Expand Up @@ -401,6 +409,22 @@ mod tests {
assert_eq!(item_collection.items.len(), 42);
}

#[rstest]
fn search_offset(client: Client) {
let mut search = Search::default().limit(1);
search
.items
.additional_fields
.insert("offset".to_string(), 1.into());
let item_collection = client
.search("data/100-sentinel-2-items.parquet", search)
.unwrap();
assert_eq!(
item_collection.items[0].id,
"S2A_MSIL2A_20241201T175721_R141_T13TDE_20241201T213150"
);
}

#[rstest]
fn search_sortby(client: Client) {
let item_collection = client
Expand Down

0 comments on commit c34baca

Please sign in to comment.