Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregation bugfix #281

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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