Skip to content

Commit 45dee7d

Browse files
committed
move refactor aggregations
1 parent 6903791 commit 45dee7d

File tree

8 files changed

+628
-467
lines changed

8 files changed

+628
-467
lines changed

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

Lines changed: 2 additions & 458 deletions
Large diffs are not rendered by default.

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from stac_fastapi.core.extensions.aggregation import (
1818
EsAggregationExtensionGetRequest,
1919
EsAggregationExtensionPostRequest,
20-
EsAsyncAggregationClient,
2120
)
2221
from stac_fastapi.core.extensions.fields import FieldsExtension
2322
from stac_fastapi.core.rate_limit import setup_rate_limit
@@ -39,6 +38,7 @@
3938
TransactionExtension,
4039
)
4140
from stac_fastapi.extensions.third_party import BulkTransactionExtension
41+
from stac_fastapi.sfeos_helpers.aggregation import EsAsyncBaseAggregationClient
4242
from stac_fastapi.sfeos_helpers.filter import EsAsyncBaseFiltersClient
4343

4444
logging.basicConfig(level=logging.INFO)
@@ -60,7 +60,7 @@
6060
)
6161

6262
aggregation_extension = AggregationExtension(
63-
client=EsAsyncAggregationClient(
63+
client=EsAsyncBaseAggregationClient(
6464
database=database_logic, session=session, settings=settings
6565
)
6666
)

stac_fastapi/opensearch/stac_fastapi/opensearch/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from stac_fastapi.core.extensions.aggregation import (
1818
EsAggregationExtensionGetRequest,
1919
EsAggregationExtensionPostRequest,
20-
EsAsyncAggregationClient,
2120
)
2221
from stac_fastapi.core.extensions.fields import FieldsExtension
2322
from stac_fastapi.core.rate_limit import setup_rate_limit
@@ -39,6 +38,7 @@
3938
create_collection_index,
4039
create_index_templates,
4140
)
41+
from stac_fastapi.sfeos_helpers.aggregation import EsAsyncBaseAggregationClient
4242
from stac_fastapi.sfeos_helpers.filter import EsAsyncBaseFiltersClient
4343

4444
logging.basicConfig(level=logging.INFO)
@@ -60,7 +60,7 @@
6060
)
6161

6262
aggregation_extension = AggregationExtension(
63-
client=EsAsyncAggregationClient(
63+
client=EsAsyncBaseAggregationClient(
6464
database=database_logic, session=session, settings=settings
6565
)
6666
)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# STAC FastAPI Aggregation Package
2+
3+
This package contains shared aggregation functionality used by both the Elasticsearch and OpenSearch implementations of STAC FastAPI. It helps reduce code duplication and ensures consistent behavior between the two implementations.
4+
5+
## Package Structure
6+
7+
The aggregation package is organized into three main modules:
8+
9+
- **client.py**: Contains the base aggregation client implementation
10+
- `EsAsyncBaseAggregationClient`: The main class that implements the STAC aggregation extension for Elasticsearch/OpenSearch
11+
- Methods for handling aggregation requests, validating parameters, and formatting responses
12+
13+
- **format.py**: Contains functions for formatting aggregation responses
14+
- `frequency_agg`: Formats frequency distribution aggregation responses
15+
- `metric_agg`: Formats metric aggregation responses
16+
17+
- **__init__.py**: Package initialization and exports
18+
- Exports the main classes and functions for use by other modules
19+
20+
## Features
21+
22+
The aggregation package provides the following features:
23+
24+
- Support for various aggregation types:
25+
- Datetime frequency
26+
- Collection frequency
27+
- Property frequency
28+
- Geospatial grid aggregations (geohash, geohex, geotile)
29+
- Metric aggregations (min, max, etc.)
30+
31+
- Parameter validation:
32+
- Precision validation for geospatial aggregations
33+
- Interval validation for datetime aggregations
34+
35+
- Response formatting:
36+
- Consistent response structure
37+
- Proper typing and documentation
38+
39+
## Usage
40+
41+
The aggregation package is used by the Elasticsearch and OpenSearch implementations to provide aggregation functionality for STAC API. The main entry point is the `EsAsyncBaseAggregationClient` class, which is instantiated in the respective app.py files.
42+
43+
Example:
44+
```python
45+
from stac_fastapi.sfeos_helpers.aggregation import EsAsyncBaseAggregationClient
46+
47+
# Create an instance of the aggregation client
48+
aggregation_client = EsAsyncBaseAggregationClient(database)
49+
50+
# Register the aggregation extension with the API
51+
api = StacApi(
52+
...,
53+
extensions=[
54+
...,
55+
AggregationExtension(client=aggregation_client),
56+
],
57+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Shared aggregation extension methods for stac-fastapi elasticsearch and opensearch backends.
2+
3+
This module provides shared functionality for implementing the STAC API Aggregation Extension
4+
with Elasticsearch and OpenSearch. It includes:
5+
6+
1. Functions for formatting aggregation responses
7+
2. Helper functions for handling aggregation parameters
8+
3. Base implementation of the AsyncBaseAggregationClient for Elasticsearch/OpenSearch
9+
10+
The aggregation package is organized as follows:
11+
- client.py: Aggregation client implementation
12+
- format.py: Response formatting functions
13+
14+
When adding new functionality to this package, consider:
15+
1. Will this code be used by both Elasticsearch and OpenSearch implementations?
16+
2. Is the functionality stable and unlikely to diverge between implementations?
17+
3. Is the function well-documented with clear input/output contracts?
18+
19+
Function Naming Conventions:
20+
- Function names should be descriptive and indicate their purpose
21+
- Parameter names should be consistent across similar functions
22+
"""
23+
24+
from .client import EsAsyncBaseAggregationClient
25+
from .format import frequency_agg, metric_agg
26+
27+
__all__ = [
28+
"EsAsyncBaseAggregationClient",
29+
"frequency_agg",
30+
"metric_agg",
31+
]

0 commit comments

Comments
 (0)