Skip to content

Commit

Permalink
Add some simple query interface tests
Browse files Browse the repository at this point in the history
These are the advanced tests with the simple interface where
possible.
  • Loading branch information
timj committed Sep 4, 2024
1 parent 999b737 commit 539e929
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 20 deletions.
27 changes: 22 additions & 5 deletions python/lsst/daf/butler/_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,8 @@ def query_data_ids(
"""
if data_id is None:
data_id = DataCoordinate.make_empty(self.dimensions)
if order_by is None:
order_by = []
with self.query() as query:
result = (
query.where(data_id, where, bind=bind, **kwargs)
Expand All @@ -1573,6 +1575,8 @@ def query_datasets(
where: str = "",
bind: Mapping[str, Any] | None = None,
with_dimension_records: bool = False,
order_by: Iterable[str] | str | None = None,
limit: int = 20_000,
explain: bool = True,
**kwargs: Any,
) -> list[DatasetRef]:
Expand All @@ -1584,7 +1588,7 @@ def query_datasets(
Dataset type object or name to search for.
collections : collection expression, optional
A collection name or iterable of collection names to search. If not
provided, the default collections are used. See
provided, the default collections are used. Can be a wildcard. See
:ref:`daf_butler_collection_expressions` for more information.
find_first : `bool`, optional
If `True` (default), for each result data ID, only yield one
Expand All @@ -1609,6 +1613,12 @@ def query_datasets(
with_dimension_records : `bool`, optional
If `True` (default is `False`) then returned data IDs will have
dimension records.
order_by : `~collections.abc.Iterable` [`str`] or `str`, optional
Names of the columns/dimensions to use for ordering returned data
IDs. Column name can be prefixed with minus (``-``) to use
descending ordering.
limit : `int`, optional
Upper limit on the number of returned records.
explain : `bool`, optional
If `True` (default) then `EmptyQueryResultError` exception is
raised when resulting list is empty. The exception contains
Expand Down Expand Up @@ -1654,11 +1664,16 @@ def query_datasets(
"""
if data_id is None:
data_id = DataCoordinate.make_empty(self.dimensions)
if order_by is None:
order_by = []
if collections:
collections = self.collections.query(collections)
with self.query() as query:
result = query.where(data_id, where, bind=bind, **kwargs).datasets(
dataset_type,
collections=collections,
find_first=find_first,
result = (
query.where(data_id, where, bind=bind, **kwargs)
.datasets(dataset_type, collections=collections, find_first=find_first)
.order_by(*ensure_iterable(order_by))
.limit(limit)
)
if with_dimension_records:
result = result.with_dimension_records()
Expand Down Expand Up @@ -1738,6 +1753,8 @@ def query_dimension_records(
"""
if data_id is None:
data_id = DataCoordinate.make_empty(self.dimensions)
if order_by is None:
order_by = []
with self.query() as query:
result = (
query.where(data_id, where, bind=bind, **kwargs)
Expand Down
Loading

0 comments on commit 539e929

Please sign in to comment.