stac-utils / stac-rs

Tools and libraries for the SpatioTemporal Asset Catalog (STAC) specification, written in Rust
https://stac-utils.github.io/stac-rs/
Apache License 2.0
84 stars 11 forks source link

cql2 filter issues #511

Closed hrodmn closed 1 week ago

hrodmn commented 3 weeks ago

I was experimenting with using stac-rs as a STAC API server for a pgstac database and I ran into some issues when using the filter parameter.

When I run a query against a stac-fastapi-pgstac API, I get the expected result:

import httpx

get_params = { 
    "collection": "noaa-hrrr-conus-sfc", 
    "filter": "forecast:horizon = 'PT1H'",
}

get_stacfastapi_pgstac = httpx.get(
    "http://localhost:8081/search",
    params=get_params
)

for item in get_stacfastapi_pgstac.json()["features"]:
    print(item["id"])
hrrr-conus-sfc-2024-08-15T23-FH1
hrrr-conus-sfc-2024-08-15T22-FH1
hrrr-conus-sfc-2024-08-15T21-FH1
hrrr-conus-sfc-2024-08-15T20-FH1
hrrr-conus-sfc-2024-08-15T19-FH1
hrrr-conus-sfc-2024-08-15T18-FH1
hrrr-conus-sfc-2024-08-15T17-FH1
hrrr-conus-sfc-2024-08-15T16-FH1
hrrr-conus-sfc-2024-08-15T15-FH1
hrrr-conus-sfc-2024-08-15T14-FH1

When I run the same query against the stac-rs API (started with stacrs serve --pgstac postgresql://username:password@localhost:5439/postgis --verbose I get a database error:

get_stacrs = httpx.get(
    "http://localhost:7822/search",
    params=get_params,
)
> 'db error: ERROR: invalid input syntax for type boolean: "forecast:horizon = \'PT1H\'"'

It seems like something is going wrong when translating the cql2-text for pgstac.

I tried a similar test with a POST request but it looks like POST requests to /search are not yet implemented.

Here is a sample item collection with two items with different values for the forecast:horizon parameter in case that is helpful context. item_collection.json

gadomski commented 2 weeks ago

Awesome, thanks for kicking the tires @hrodmn! I haven't "officially" implemented the filter extension yet (https://github.com/stac-utils/stac-rs/tree/main/crates/server#backends) but this is a good note to either implement or explicitly disallow. Shouldn't be hard to implement so I'll probably do that.