Skip to content

Commit

Permalink
feat: update geoarrow and duckdb (#562)
Browse files Browse the repository at this point in the history
- Closes #385
  • Loading branch information
gadomski authored Dec 24, 2024
1 parent 55703ce commit 0a5a045
Show file tree
Hide file tree
Showing 27 changed files with 517 additions and 661 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
working-directory: crates/cli
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.81
- uses: Swatinem/rust-cache@v2
- name: Test
run: cargo test -p stac-cli
Expand All @@ -71,7 +70,6 @@ jobs:
working-directory: crates/cli
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.81
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -129,7 +127,7 @@ jobs:
with:
enable-cache: true
- name: Test
run: cargo test -p pgstac
run: cargo test -p pgstac --all-features
- name: Install Python dependencies
run: uv sync --group stac-api-validator
- name: Validate
Expand Down
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ homepage = "https://stac-utils.github.io/stac-rs"
repository = "https://github.com/stac-utils/stac-rs"
license = "MIT OR Apache-2.0"
categories = ["science", "data-structures"]
rust-version = "1.80"
rust-version = "1.82"

[workspace.dependencies]
arrow = "52.2"
arrow-array = "52.2"
arrow-cast = "52.2"
arrow-json = "52.2"
arrow-schema = "52.2"
arrow = "53.1.0"
arrow-array = "53.1.0"
arrow-cast = "53.1.0"
arrow-json = "53.1.0"
arrow-schema = "53.1.0"
assert-json-diff = "2.0"
assert_cmd = "2.0"
async-stream = "0.3.6"
Expand All @@ -43,23 +43,23 @@ bytes = "1.7"
chrono = "0.4.38"
clap = "4.5"
cql2 = "0.3.0"
duckdb = "=1.0.0"
duckdb = "1.1.1"
fluent-uri = "0.3.1"
futures = "0.3.31"
geo = "0.29.3"
geo-types = "0.7.13"
geoarrow = "0.3.0"
geoarrow = "0.4.0-beta.3"
geojson = "0.24.1"
http = "1.1"
jsonschema = { version = "0.22.3", default-features = false }
libduckdb-sys = "=1.0.0"
libduckdb-sys = "1.1.1"
log = "0.4.22"
mime = "0.3.17"
mockito = "1.5"
object_store = "0.11.0"
openssl = { version = "0.10.68", features = ["vendored"] }
openssl-src = "=300.4.1" # joinked from https://github.com/iopsystems/rpc-perf/commit/705b290d2105af6f33150da04b217422c6d68701#diff-2e9d962a08321605940b5a657135052fbcef87b5e360662bb527c96d9a615542R41 to cross-compile Python
parquet = { version = "52.2", default-features = false }
parquet = { version = "53.1.0", default-features = false }
pgstac = { version = "0.2.2", path = "crates/pgstac" }
pyo3 = "0.23.3"
pythonize = "0.23.0"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

Command Line Interface (CLI) and Rust libraries for the [SpatioTemporal Asset Catalog (STAC)](https://stacspec.org/) specification.

There's a couple Python projects based on **stac-rs** that might be of interest to you, as well:

- [stacrs](https://github.com/gadomski/stacrs) provides a Python API to **stac-rs**, including
- Reading and writing [stac-geoparquet](https://github.com/stac-utils/stac-geoparquet)
- Migrating to [STAC v1.1](https://github.com/radiantearth/stac-spec/releases/tag/v1.1.0)
- [More...](https://www.gadom.ski/posts/stacrs-python-v0-1/)
- [pgstacrs](https://github.com/stac-utils/pgstacrs) is a Python library for working with [pgstac](https://github.com/stac-utils/pgstac)

## Command line interface

Our command line interface (CLI) can query STAC APIs, validate STAC, and more.
Expand Down
8 changes: 8 additions & 0 deletions crates/api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- Convenience methods on `Search` ([#562](https://github.com/stac-utils/stac-rs/pull/562))

### Changed

- Many vectors on `Search` and `Items` are no longer `Options` ([#562](https://github.com/stac-utils/stac-rs/pull/562))

## [0.6.2] - 2024-11-12

### Added
Expand Down
6 changes: 3 additions & 3 deletions crates/api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Client {
/// use futures::StreamExt;
///
/// let client = Client::new("https://planetarycomputer.microsoft.com/api/stac/v1").unwrap();
/// let mut search = Search { collections: Some(vec!["sentinel-2-l2a".to_string()]), ..Default::default() };
/// let mut search = Search { collections: vec!["sentinel-2-l2a".to_string()], ..Default::default() };
/// # tokio_test::block_on(async {
/// let items: Vec<_> = client
/// .search(search)
Expand Down Expand Up @@ -272,7 +272,7 @@ impl BlockingClient {
/// use stac_api::{Search, BlockingClient};
///
/// let client = BlockingClient::new("https://planetarycomputer.microsoft.com/api/stac/v1").unwrap();
/// let mut search = Search { collections: Some(vec!["sentinel-2-l2a".to_string()]), ..Default::default() };
/// let mut search = Search { collections: vec!["sentinel-2-l2a".to_string()], ..Default::default() };
/// let items: Vec<_> = client
/// .search(search)
/// .unwrap()
Expand Down Expand Up @@ -430,7 +430,7 @@ mod tests {

let client = Client::new(&server.url()).unwrap();
let mut search = Search {
collections: Some(vec!["sentinel-2-l2a".to_string()]),
collections: vec!["sentinel-2-l2a".to_string()],
..Default::default()
};
search.items.limit = Some(1);
Expand Down
2 changes: 1 addition & 1 deletion crates/api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum Error {

/// [cql2::Error]
#[error(transparent)]
Cql2(#[from] cql2::Error),
Cql2(#[from] Box<cql2::Error>),

/// [geojson::Error]
#[error(transparent)]
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Filter {
match self {
Filter::Cql2Json(_) => Ok(self),
Filter::Cql2Text(text) => {
let expr = cql2::parse_text(&text)?;
let expr = cql2::parse_text(&text).map_err(Box::new)?;
Ok(Filter::Cql2Json(serde_json::from_value(
serde_json::to_value(expr)?,
)?))
Expand All @@ -37,7 +37,7 @@ impl Filter {
Filter::Cql2Text(_) => Ok(self),
Filter::Cql2Json(json) => {
let expr: Expr = serde_json::from_value(Value::Object(json))?;
Ok(Filter::Cql2Text(expr.to_text()?))
Ok(Filter::Cql2Text(expr.to_text().map_err(Box::new)?))
}
}
}
Expand Down
54 changes: 30 additions & 24 deletions crates/api/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub struct Items {
pub fields: Option<Fields>,

/// Fields by which to sort results.
#[serde(skip_serializing_if = "Option::is_none")]
pub sortby: Option<Vec<Sortby>>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub sortby: Vec<Sortby>,

/// Recommended to not be passed, but server must only accept
/// <http://www.opengis.net/def/crs/OGC/1.3/CRS84> as a valid value, may
Expand Down Expand Up @@ -281,14 +281,14 @@ impl Items {
/// ..Default::default()
/// };
/// let search = items.search_collection("collection-id");
/// assert_eq!(search.collections.unwrap(), vec!["collection-id"]);
/// assert_eq!(search.collections, vec!["collection-id"]);
/// ```
pub fn search_collection(self, collection_id: impl ToString) -> Search {
Search {
items: self,
intersects: None,
ids: None,
collections: Some(vec![collection_id.to_string()]),
ids: Vec::new(),
collections: vec![collection_id.to_string()],
}
}

Expand Down Expand Up @@ -327,13 +327,18 @@ impl TryFrom<Items> for GetItems {
}),
datetime: items.datetime,
fields: items.fields.map(|fields| fields.to_string()),
sortby: items.sortby.map(|sortby| {
sortby
.into_iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(",")
}),
sortby: if items.sortby.is_empty() {
None
} else {
Some(
items
.sortby
.into_iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(","),
)
},
filter_crs: items.filter_crs,
filter_lang: if filter.is_some() {
Some("cql2-text".to_string())
Expand Down Expand Up @@ -364,15 +369,16 @@ impl TryFrom<GetItems> for Items {
None
};

let sortby = if let Some(value) = get_items.sortby {
let mut sortby = Vec::new();
for s in value.split(',') {
sortby.push(s.parse().expect("infallible"));
}
Some(sortby)
} else {
None
};
let sortby = get_items
.sortby
.map(|s| {
let mut sortby = Vec::new();
for s in s.split(',') {
sortby.push(s.parse().expect("infallible"));
}
sortby
})
.unwrap_or_default();

Ok(Items {
limit: get_items.limit.map(|limit| limit.parse()).transpose()?,
Expand Down Expand Up @@ -452,7 +458,7 @@ mod tests {
}
);
assert_eq!(
items.sortby.unwrap(),
items.sortby,
vec![Sortby {
field: "foo".to_string(),
direction: Direction::Descending,
Expand All @@ -478,10 +484,10 @@ mod tests {
include: vec!["foo".to_string()],
exclude: vec!["bar".to_string()],
}),
sortby: Some(vec![Sortby {
sortby: vec![Sortby {
field: "foo".to_string(),
direction: Direction::Descending,
}]),
}],
filter_crs: None,
filter: Some(Filter::Cql2Text("dummy text".to_string())),
query: None,
Expand Down
18 changes: 10 additions & 8 deletions crates/api/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ pub fn search<'py>(
.map(|query| pythonize::depythonize(&query))
.transpose()?;
let bbox = bbox.map(Bbox::try_from).transpose().map_err(Error::from)?;
let sortby = sortby.map(|sortby| {
Vec::<String>::from(sortby)
.into_iter()
.map(|s| s.parse::<Sortby>().unwrap()) // the parse is infallible
.collect::<Vec<_>>()
});
let sortby = sortby
.map(|sortby| {
Vec::<String>::from(sortby)
.into_iter()
.map(|s| s.parse::<Sortby>().unwrap()) // the parse is infallible
.collect::<Vec<_>>()
})
.unwrap_or_default();
let filter = filter
.map(|filter| match filter {
StringOrDict::Dict(cql_json) => pythonize::depythonize(&cql_json).map(Filter::Cql2Json),
Expand Down Expand Up @@ -80,8 +82,8 @@ pub fn search<'py>(
.map_err(|err| PyValueError::new_err(err.to_string())),
})
.transpose()?;
let ids = ids.map(|ids| ids.into());
let collections = collections.map(|ids| ids.into());
let ids = ids.map(|ids| ids.into()).unwrap_or_default();
let collections = collections.map(|ids| ids.into()).unwrap_or_default();
Ok(Search {
items,
intersects,
Expand Down
Loading

0 comments on commit 0a5a045

Please sign in to comment.