From c88fcd02c6999e17c0ecfce8310afb3cc60d8a1d Mon Sep 17 00:00:00 2001 From: James Date: Mon, 22 Jul 2024 11:32:54 -0400 Subject: [PATCH 1/3] fix filter condition --- .../stac_fastapi/core/extensions/aggregation.py | 2 ++ stac_fastapi/tests/extensions/test_aggregation.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py b/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py index ddab6829..48ab8fa6 100644 --- a/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py +++ b/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py @@ -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 diff --git a/stac_fastapi/tests/extensions/test_aggregation.py b/stac_fastapi/tests/extensions/test_aggregation.py index 9ee4c708..dd471159 100644 --- a/stac_fastapi/tests/extensions/test_aggregation.py +++ b/stac_fastapi/tests/extensions/test_aggregation.py @@ -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 From 7e548f99f23dcea8546e680df26d608a99923294 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 22 Jul 2024 16:17:47 -0400 Subject: [PATCH 2/3] fix cql2text parsing --- stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py b/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py index 48ab8fa6..facc8bcc 100644 --- a/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py +++ b/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py @@ -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)) From 514465c52bb2a66c9ef197b40ffd605f64555aa3 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 23 Jul 2024 09:22:49 -0400 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 901e4d0d..870366c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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