Skip to content

Commit

Permalink
Add dataset query support to new query system.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Dec 17, 2023
1 parent 777da33 commit 232b56d
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 10 deletions.
48 changes: 47 additions & 1 deletion python/lsst/daf/butler/queries/_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
from .._query import Query
from ..dimensions import DataCoordinate, DataId, DataIdValue, DimensionGroup
from .data_coordinate_results import DataCoordinateResultSpec, RelationDataCoordinateQueryResults
from .dataset_results import (

Check warning on line 38 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L35-L38

Added lines #L35 - L38 were not covered by tests
ChainedDatasetQueryResults,
DatasetRefResultSpec,
RelationSingleTypeDatasetQueryResults,
)
from .dimension_record_results import DimensionRecordResultSpec, RelationDimensionRecordQueryResults
from .driver import QueryDriver
from .expression_factory import ExpressionFactory, ExpressionProxy
Expand Down Expand Up @@ -171,6 +176,8 @@ def data_ids(
)
return RelationDataCoordinateQueryResults(self._driver, tree, result_spec)

Check warning on line 177 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L177

Added line #L177 was not covered by tests

# TODO add typing.overload variants for single-dataset-type and patterns.

def datasets(

Check warning on line 181 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L181

Added line #L181 was not covered by tests
self,
dataset_type: Any,
Expand All @@ -183,7 +190,46 @@ def datasets(
**kwargs: Any,
) -> DatasetQueryResults:
# Docstring inherited.
raise NotImplementedError("TODO")
resolved_dataset_types = self._driver.resolve_dataset_type_wildcard(dataset_type)
data_id = DataCoordinate.standardize(data_id, universe=self._driver.universe, **kwargs)
where_terms = convert_where_args(self._tree, where, data_id, bind=bind, **kwargs)
single_type_results: list[RelationSingleTypeDatasetQueryResults] = []

Check warning on line 196 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L193-L196

Added lines #L193 - L196 were not covered by tests
for name, resolved_dataset_type in resolved_dataset_types.items():
tree = self._tree

Check warning on line 198 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L198

Added line #L198 was not covered by tests
if name not in tree.available_dataset_types:
resolved_collections, collections_ordered = self._driver.resolve_collection_wildcard(

Check warning on line 200 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L200

Added line #L200 was not covered by tests
collections
)
if find_first and not collections_ordered:
raise InvalidRelationError(

Check warning on line 204 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L204

Added line #L204 was not covered by tests
f"Unordered collections argument {collections} requires find_first=False."
)
tree = tree.join(

Check warning on line 207 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L207

Added line #L207 was not covered by tests
DatasetSearch.model_construct(
dataset_type=name,
dimensions=resolved_dataset_type.dimensions.as_group(),
collections=tuple(resolved_collections),
)
)
elif collections is not None:
raise InvalidRelationError(

Check warning on line 215 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L215

Added line #L215 was not covered by tests
f"Dataset type {name!r} was already joined into this query but new collections "
f"{collections!r} were still provided."
)
if where_terms:
tree = tree.where(*where_terms)

Check warning on line 220 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L220

Added line #L220 was not covered by tests
if find_first:
tree = tree.find_first(name, resolved_dataset_type.dimensions.as_group())
spec = DatasetRefResultSpec.model_construct(

Check warning on line 223 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L222-L223

Added lines #L222 - L223 were not covered by tests
dataset_type=resolved_dataset_type, include_dimension_records=self._include_dimension_records
)
single_type_results.append(

Check warning on line 226 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L226

Added line #L226 was not covered by tests
RelationSingleTypeDatasetQueryResults(self._driver, tree=tree, spec=spec)
)
if len(single_type_results) == 1:
return single_type_results[0]

Check warning on line 230 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L230

Added line #L230 was not covered by tests
else:
return ChainedDatasetQueryResults(tuple(single_type_results))

Check warning on line 232 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L232

Added line #L232 was not covered by tests

def dimension_records(

Check warning on line 234 in python/lsst/daf/butler/queries/_query.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/_query.py#L234

Added line #L234 was not covered by tests
self,
Expand Down
8 changes: 5 additions & 3 deletions python/lsst/daf/butler/queries/data_coordinate_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DataCoordinateResultPage(pydantic.BaseModel):


class RelationDataCoordinateQueryResults(DataCoordinateQueryResults):

Check warning on line 79 in python/lsst/daf/butler/queries/data_coordinate_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/data_coordinate_results.py#L79

Added line #L79 was not covered by tests
"""Implementation of DataCoordinateQueryResults for the relation-based
"""Implementation of `DataCoordinateQueryResults` for the relation-based
query system.
Parameters
Expand Down Expand Up @@ -145,7 +145,9 @@ def expanded(self) -> DataCoordinateQueryResults:
return RelationDataCoordinateQueryResults(

Check warning on line 145 in python/lsst/daf/butler/queries/data_coordinate_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/data_coordinate_results.py#L144-L145

Added lines #L144 - L145 were not covered by tests
self._driver,
tree=self._tree,
spec=DataCoordinateResultSpec(dimensions=self._spec.dimensions, include_dimension_records=True),
spec=DataCoordinateResultSpec.model_construct(
dimensions=self._spec.dimensions, include_dimension_records=True
),
)

def subset(

Check warning on line 153 in python/lsst/daf/butler/queries/data_coordinate_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/data_coordinate_results.py#L153

Added line #L153 was not covered by tests
Expand All @@ -170,7 +172,7 @@ def subset(
return RelationDataCoordinateQueryResults(

Check warning on line 172 in python/lsst/daf/butler/queries/data_coordinate_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/data_coordinate_results.py#L172

Added line #L172 was not covered by tests
self._driver,
tree=self._tree,
spec=DataCoordinateResultSpec(
spec=DataCoordinateResultSpec.model_construct(
dimensions=dimensions, include_dimension_records=self._spec.include_dimension_records
),
)
Expand Down
183 changes: 178 additions & 5 deletions python/lsst/daf/butler/queries/dataset_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,34 @@
__all__ = (

Check warning on line 30 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L30

Added line #L30 was not covered by tests
"DatasetRefResultSpec",
"DatasetRefResultPage",
"RelationSingleTypeDatasetQueryResults",
)

import itertools
from collections.abc import Iterable, Iterator
from contextlib import ExitStack, contextmanager
from typing import Literal

Check warning on line 39 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L36-L39

Added lines #L36 - L39 were not covered by tests

import pydantic

Check warning on line 41 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L41

Added line #L41 was not covered by tests

from .._dataset_ref import DatasetRef
from ..dimensions import DimensionGroup
from .driver import PageKey
from .._dataset_type import DatasetType
from .._query_results import SingleTypeDatasetQueryResults
from .data_coordinate_results import (

Check warning on line 46 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L43-L46

Added lines #L43 - L46 were not covered by tests
DataCoordinateResultSpec,
DatasetQueryResults,
RelationDataCoordinateQueryResults,
)
from .driver import PageKey, QueryDriver
from .relation_tree import Materialization, RootRelation, make_unit_relation

Check warning on line 52 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L51-L52

Added lines #L51 - L52 were not covered by tests


class DatasetRefResultSpec(pydantic.BaseModel):

Check warning on line 55 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L55

Added line #L55 was not covered by tests
"""Specification for a query that yields `DatasetRef` objects."""

result_type: Literal["dataset_ref"] = "dataset_ref"
dataset_type_name: str | None
dimensions: DimensionGroup
with_dimension_records: bool
dataset_type: DatasetType
include_dimension_records: bool

Check warning on line 60 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L58-L60

Added lines #L58 - L60 were not covered by tests


class DatasetRefResultPage(pydantic.BaseModel):

Check warning on line 63 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L63

Added line #L63 was not covered by tests
Expand All @@ -60,3 +70,166 @@ class DatasetRefResultPage(pydantic.BaseModel):
# attached DimensionRecords and is Pydantic-friendly. Right now this model
# isn't actually serializable.
rows: list[DatasetRef]

Check warning on line 72 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L72

Added line #L72 was not covered by tests


class RelationSingleTypeDatasetQueryResults(SingleTypeDatasetQueryResults):

Check warning on line 75 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L75

Added line #L75 was not covered by tests
"""Implementation of `SingleTypeDatasetQueryResults` for the relation-based
query system.
Parameters
----------
driver : `QueryDriver`
Implementation object that knows how to actually execute queries.
tree : `RootRelation`
Description of the query as a tree of relation operations. The
instance returned directly by the `Butler._query` entry point should be
constructed via `make_unit_relation`.
spec : `DatasetRefResultSpec`
Specification for the details of the dataset references to return.
Notes
-----
Ideally this will eventually just be "SingleTypeDatasetQueryResults",
because we won't need an ABC if this is the only implementation.
"""

def __init__(self, driver: QueryDriver, tree: RootRelation, spec: DatasetRefResultSpec):
self._driver = driver
self._tree = tree
self._spec = spec

Check warning on line 99 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L96-L99

Added lines #L96 - L99 were not covered by tests

def __iter__(self) -> Iterator[DatasetRef]:
page = self._driver.execute(self._tree, self._spec)
yield from page.rows

Check warning on line 103 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L101-L103

Added lines #L101 - L103 were not covered by tests
while page.next_key is not None:
page = self._driver.fetch_next_page(self._spec, page.next_key)
yield from page.rows

Check warning on line 106 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L105-L106

Added lines #L105 - L106 were not covered by tests

@contextmanager

Check warning on line 108 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L108

Added line #L108 was not covered by tests
def materialize(self) -> Iterator[RelationSingleTypeDatasetQueryResults]:
# Docstring inherited from DatasetQueryResults.
key = self._driver.materialize(self._tree, frozenset())
yield RelationSingleTypeDatasetQueryResults(

Check warning on line 112 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L111-L112

Added lines #L111 - L112 were not covered by tests
self._driver,
tree=make_unit_relation(self._driver.universe).join(
Materialization.model_construct(
key=key, operand=self._tree, dataset_types=frozenset({self.dataset_type.name})
)
),
spec=self._spec,
)
# TODO: Right now we just rely on the QueryDriver context instead of
# using this one. If we want this to remain a context manager, we
# should make it do something, e.g. by adding QueryDriver method to
# drop a materialization.

@property

Check warning on line 126 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L126

Added line #L126 was not covered by tests
def dataset_type(self) -> DatasetType:
# Docstring inherited.
return self._spec.dataset_type

Check warning on line 129 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L129

Added line #L129 was not covered by tests

@property

Check warning on line 131 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L131

Added line #L131 was not covered by tests
def data_ids(self) -> RelationDataCoordinateQueryResults:
# Docstring inherited.
return RelationDataCoordinateQueryResults(

Check warning on line 134 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L134

Added line #L134 was not covered by tests
self._driver,
tree=self._tree,
spec=DataCoordinateResultSpec.model_construct(
dimensions=self.dataset_type.dimensions.as_group(),
include_dimension_records=self._spec.include_dimension_records,
),
)

def expanded(self) -> RelationSingleTypeDatasetQueryResults:

Check warning on line 143 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L143

Added line #L143 was not covered by tests
# Docstring inherited.
if self._spec.include_dimension_records:
return self
return RelationSingleTypeDatasetQueryResults(

Check warning on line 147 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L146-L147

Added lines #L146 - L147 were not covered by tests
self._driver,
tree=self._tree,
spec=DatasetRefResultSpec.model_construct(
dataset_type=self.dataset_type, include_dimension_records=True
),
)

def by_dataset_type(self) -> Iterator[SingleTypeDatasetQueryResults]:

Check warning on line 155 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L155

Added line #L155 was not covered by tests
# Docstring inherited.
return iter((self,))

Check warning on line 157 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L157

Added line #L157 was not covered by tests

def count(self, *, exact: bool = True, discard: bool = False) -> int:

Check warning on line 159 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L159

Added line #L159 was not covered by tests
# Docstring inherited.
return self._driver.count(self._tree, exact=exact, discard=discard)

Check warning on line 161 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L161

Added line #L161 was not covered by tests

def any(self, *, execute: bool = True, exact: bool = True) -> bool:

Check warning on line 163 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L163

Added line #L163 was not covered by tests
# Docstring inherited.
return self._driver.any(self._tree, execute=execute, exact=exact)

Check warning on line 165 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L165

Added line #L165 was not covered by tests

def explain_no_results(self, execute: bool = True) -> Iterable[str]:

Check warning on line 167 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L167

Added line #L167 was not covered by tests
# Docstring inherited.
return self._driver.explain_no_results(self._tree, execute=execute)

Check warning on line 169 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L169

Added line #L169 was not covered by tests


class ChainedDatasetQueryResults(DatasetQueryResults):

Check warning on line 172 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L172

Added line #L172 was not covered by tests
"""Implementation of `DatasetQueryResults` that delegates to a sequence
of `SingleTypeDatasetQueryResults`.
Parameters
----------
by_dataset_type : `tuple` [ `SingleTypeDatasetQueryResults` ]
Tuple of single-dataset-type query result objects to combine.
Notes
-----
Ideally this will eventually just be "DatasetQueryResults", because we
won't need an ABC if this is the only implementation.
"""

def __init__(self, by_dataset_type: tuple[SingleTypeDatasetQueryResults, ...]):
self._by_dataset_type = by_dataset_type

Check warning on line 188 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L187-L188

Added lines #L187 - L188 were not covered by tests

def __iter__(self) -> Iterator[DatasetRef]:
return itertools.chain.from_iterable(self._by_dataset_type)

Check warning on line 191 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L190-L191

Added lines #L190 - L191 were not covered by tests

def by_dataset_type(self) -> Iterator[SingleTypeDatasetQueryResults]:

Check warning on line 193 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L193

Added line #L193 was not covered by tests
# Docstring inherited.
return iter(self._by_dataset_type)

Check warning on line 195 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L195

Added line #L195 was not covered by tests

@contextmanager

Check warning on line 197 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L197

Added line #L197 was not covered by tests
def materialize(self) -> Iterator[DatasetQueryResults]:
# Docstring inherited.
with ExitStack() as exit_stack:
yield ChainedDatasetQueryResults(
tuple(
[
exit_stack.enter_context(single_type_results.materialize())
for single_type_results in self._by_dataset_type
]
)
)

def expanded(self) -> ChainedDatasetQueryResults:

Check warning on line 210 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L210

Added line #L210 was not covered by tests
# Docstring inherited.
return ChainedDatasetQueryResults(
tuple([single_type_results.expanded() for single_type_results in self._by_dataset_type])
)

def count(self, *, exact: bool = True, discard: bool = False) -> int:

Check warning on line 216 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L216

Added line #L216 was not covered by tests
# Docstring inherited.
return sum(
single_type_results.count(exact=exact, discard=discard)
for single_type_results in self._by_dataset_type
)

def any(self, *, execute: bool = True, exact: bool = True) -> bool:

Check warning on line 223 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L223

Added line #L223 was not covered by tests
# Docstring inherited.
return any(
single_type_results.any(execute=execute, exact=exact)
for single_type_results in self._by_dataset_type
)

def explain_no_results(self, execute: bool = True) -> Iterable[str]:

Check warning on line 230 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L230

Added line #L230 was not covered by tests
# Docstring inherited.
messages: list[str] = []

Check warning on line 232 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L232

Added line #L232 was not covered by tests
for single_type_results in self._by_dataset_type:
messages.extend(single_type_results.explain_no_results(execute=execute))
return messages

Check warning on line 235 in python/lsst/daf/butler/queries/dataset_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/dataset_results.py#L234-L235

Added lines #L234 - L235 were not covered by tests
51 changes: 50 additions & 1 deletion python/lsst/daf/butler/queries/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@
from abc import abstractmethod
from collections.abc import Iterable
from contextlib import AbstractContextManager
from typing import Annotated, TypeAlias, Union, overload
from typing import TYPE_CHECKING, Annotated, Any, TypeAlias, Union, overload

Check warning on line 36 in python/lsst/daf/butler/queries/driver.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/driver.py#L32-L36

Added lines #L32 - L36 were not covered by tests

import pydantic

Check warning on line 38 in python/lsst/daf/butler/queries/driver.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/driver.py#L38

Added line #L38 was not covered by tests

from .._dataset_type import DatasetType
from ..dimensions import DataIdValue, DimensionGroup, DimensionUniverse
from .data_coordinate_results import DataCoordinateResultPage, DataCoordinateResultSpec
from .dataset_results import DatasetRefResultPage, DatasetRefResultSpec
from .dimension_record_results import DimensionRecordResultPage, DimensionRecordResultSpec
from .general_results import GeneralResultPage, GeneralResultSpec
from .relation_tree import MaterializationKey, RootRelation, UploadKey

Check warning on line 46 in python/lsst/daf/butler/queries/driver.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/driver.py#L40-L46

Added lines #L40 - L46 were not covered by tests

if TYPE_CHECKING:
from ..registry import CollectionArgType

PageKey: TypeAlias = uuid.UUID

Check warning on line 51 in python/lsst/daf/butler/queries/driver.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/driver.py#L51

Added line #L51 was not covered by tests


Expand All @@ -63,6 +67,8 @@ class QueryDriver(AbstractContextManager[None]):
"""Base class for the implementation object inside `RelationQuery` objects
that is specialized for DirectButler vs. RemoteButler.
Notes
-----
Implementations should be context managers. This allows them to manage the
lifetime of server-side state, such as:
Expand Down Expand Up @@ -300,6 +306,49 @@ def explain_no_results(self, tree: RootRelation, execute: bool) -> Iterable[str]
"""
raise NotImplementedError()

@abstractmethod

Check warning on line 309 in python/lsst/daf/butler/queries/driver.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/driver.py#L309

Added line #L309 was not covered by tests
def resolve_collection_wildcard(
self, collections: CollectionArgType | None = None
) -> tuple[list[str], bool]:
"""Resolve a collection argument into a sequence of collection names.
Parameters
----------
collections
Collection search path argument. If `None`, the default
collections for the client should be used, if there are any.
Returns
-------
matched : `list` [ `str` ]
Matching collection names. `~CollectionType.CHAINED` collections
are included directly rather than flattened.
ordered : `bool`
If `True`, the expression specified an order that can be used in
a find-first search.
"""
raise NotImplementedError()

@abstractmethod

Check warning on line 332 in python/lsst/daf/butler/queries/driver.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/driver.py#L332

Added line #L332 was not covered by tests
def resolve_dataset_type_wildcard(self, dataset_type: Any) -> dict[str, DatasetType]:
"""Resolve a dataset type argument into a mapping of `DatasetType`
objects.
Parameters
----------
dataset_type
Dataset type name, object, or wildcard to resolve.
Returns
-------
matched : `dict` [ `str`, `DatasetType` ]
Mapping from dataset type name to dataset type. Storage classes
passed in should be preserved, but component dataset types should
result in an exception.
"""
raise NotImplementedError()

@abstractmethod

Check warning on line 351 in python/lsst/daf/butler/queries/driver.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/queries/driver.py#L351

Added line #L351 was not covered by tests
def get_dataset_dimensions(self, name: str) -> DimensionGroup:
"""Return the dimensions for a dataset type."""
raise NotImplementedError()

0 comments on commit 232b56d

Please sign in to comment.