diff --git a/datacube/drivers/postgres/_api.py b/datacube/drivers/postgres/_api.py index 0129c2e91..d32034646 100644 --- a/datacube/drivers/postgres/_api.py +++ b/datacube/drivers/postgres/_api.py @@ -608,7 +608,7 @@ def _ob_exprs(o): if not source_exprs: return ( select( - *select_columns + *select_columns # type: ignore[arg-type] ).select_from( from_expression ).where( diff --git a/datacube/index/abstract.py b/datacube/index/abstract.py index a48131a18..05f3cab1e 100644 --- a/datacube/index/abstract.py +++ b/datacube/index/abstract.py @@ -16,6 +16,7 @@ from uuid import UUID from datetime import timedelta from deprecat import deprecat +from sqlalchemy import Function from odc.geo import CRS, Geometry from datacube.cfg.api import ODCEnvironment, ODCOptionHandler @@ -1763,7 +1764,7 @@ def search_returning(self, custom_offsets: Mapping[str, Offset] | None = None, limit: int | None = None, archived: bool | None = False, - order_by: Iterable[str | Field | None] = None, + order_by: Iterable[str | Field | Function] | None = None, **query: QueryField ) -> Iterable[tuple]: """ @@ -1783,8 +1784,8 @@ def search_returning(self, :param archived: False (default): Return active datasets only. None: Include archived and active datasets. True: Return archived datasets only. - :param order_by: a field name or field by which to sort output. None is unsorted and may allow faster return - of first result depending on the index driver's implementation. + :param order_by: a field name, field, or function by which to sort output. None is unsorted and may allow + faster return of first result depending on the index driver's implementation. :param geopolygon: Spatial search polygon (only supported if index supports_spatial_indexes) :param query: search query parameters :return: Namedtuple of requested fields, for each matching dataset. diff --git a/datacube/index/memory/_datasets.py b/datacube/index/memory/_datasets.py index b9e4ae0e4..0a56cef0f 100755 --- a/datacube/index/memory/_datasets.py +++ b/datacube/index/memory/_datasets.py @@ -13,6 +13,7 @@ from time import monotonic from typing import (Any, Callable, Iterable, Mapping, Sequence, cast) from uuid import UUID +from sqlalchemy import Function from datacube.migration import ODC2DeprecationWarning from datacube.index import fields @@ -607,7 +608,7 @@ def search_returning(self, custom_offsets: Mapping[str, Offset] | None = None, limit: int | None = None, archived: bool | None = False, - order_by: str | Field | None = None, + order_by: Iterable[str | Field | Function] | None = None, **query: QueryField) -> Iterable[tuple]: if "geopolygon" in query: raise NotImplementedError("Spatial search index API not supported by this index.")