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 7a907f4
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 18 deletions.
23 changes: 19 additions & 4 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 Down Expand Up @@ -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,14 @@ def query_datasets(
"""
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).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 +1751,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 7a907f4

Please sign in to comment.