Skip to content

Commit

Permalink
Aggregation bugfix (#281)
Browse files Browse the repository at this point in the history
**Description:**
- Two bug fixes for the aggregation logic

**PR Checklist:**

- [x] Code is formatted and linted (run `pre-commit run --all-files`)
- [x] Tests pass (run `make test`)
- [x] Documentation has been updated to reflect changes, if applicable
- [x] Changes are added to the changelog
  • Loading branch information
jamesfisher-geo authored Jul 23, 2024
1 parent f2665ca commit 3777f21
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed
- Aggregation bug fixes [#281](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/281)

## [v3.0.0a3] - 2024-07-17

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def metric_agg(self, es_aggs, name, data_type):
def get_filter(self, filter, filter_lang):
"""Format the filter parameter in cql2-json or cql2-text."""
if filter_lang == "cql2-text":
return orjson.loads(unquote_plus(to_cql2(parse_cql2_text(filter))))
return orjson.loads(to_cql2(parse_cql2_text(filter)))
elif filter_lang == "cql2-json":
if isinstance(filter, str):
return orjson.loads(unquote_plus(filter))
Expand Down Expand Up @@ -447,6 +447,8 @@ async def aggregate(
status_code=400,
detail=f"Aggregation {agg_name} not supported at catalog level",
)

if aggregate_request.filter:
try:
search = self.database.apply_cql2_filter(
search, aggregate_request.filter
Expand Down
13 changes: 13 additions & 0 deletions stac_fastapi/tests/extensions/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ async def test_aggregate_filter_extension_eq_post(app_client, ctx):
assert resp.json()["aggregations"][0]["value"] == 1


@pytest.mark.asyncio
async def test_aggregate_filter_extension_neq_post(app_client, ctx):
params = {
"filter": {"op": "<>", "args": [{"property": "id"}, ctx.item["id"]]},
"filter-lang": "cql2-json",
"aggregations": ["total_count"],
"collections": [ctx.item["collection"]],
}
resp = await app_client.post("/aggregate", json=params)
assert resp.status_code == 200
assert resp.json()["aggregations"][0]["value"] == 0


@pytest.mark.asyncio
async def test_aggregate_extension_gte_get(app_client, ctx):
# there's one item that can match, so one of these queries should match it and the other shouldn't
Expand Down

0 comments on commit 3777f21

Please sign in to comment.