Skip to content

Commit 3777f21

Browse files
Aggregation bugfix (#281)
**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
1 parent f2665ca commit 3777f21

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Changed
11+
- Aggregation bug fixes [#281](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/281)
12+
1013
## [v3.0.0a3] - 2024-07-17
1114

1215
### Added

stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def metric_agg(self, es_aggs, name, data_type):
271271
def get_filter(self, filter, filter_lang):
272272
"""Format the filter parameter in cql2-json or cql2-text."""
273273
if filter_lang == "cql2-text":
274-
return orjson.loads(unquote_plus(to_cql2(parse_cql2_text(filter))))
274+
return orjson.loads(to_cql2(parse_cql2_text(filter)))
275275
elif filter_lang == "cql2-json":
276276
if isinstance(filter, str):
277277
return orjson.loads(unquote_plus(filter))
@@ -447,6 +447,8 @@ async def aggregate(
447447
status_code=400,
448448
detail=f"Aggregation {agg_name} not supported at catalog level",
449449
)
450+
451+
if aggregate_request.filter:
450452
try:
451453
search = self.database.apply_cql2_filter(
452454
search, aggregate_request.filter

stac_fastapi/tests/extensions/test_aggregation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,19 @@ async def test_aggregate_filter_extension_eq_post(app_client, ctx):
176176
assert resp.json()["aggregations"][0]["value"] == 1
177177

178178

179+
@pytest.mark.asyncio
180+
async def test_aggregate_filter_extension_neq_post(app_client, ctx):
181+
params = {
182+
"filter": {"op": "<>", "args": [{"property": "id"}, ctx.item["id"]]},
183+
"filter-lang": "cql2-json",
184+
"aggregations": ["total_count"],
185+
"collections": [ctx.item["collection"]],
186+
}
187+
resp = await app_client.post("/aggregate", json=params)
188+
assert resp.status_code == 200
189+
assert resp.json()["aggregations"][0]["value"] == 0
190+
191+
179192
@pytest.mark.asyncio
180193
async def test_aggregate_extension_gte_get(app_client, ctx):
181194
# there's one item that can match, so one of these queries should match it and the other shouldn't

0 commit comments

Comments
 (0)