Coverage for python / lsst / daf / butler / queries / _dimension_record_query_results.py: 52%
36 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-24 08:17 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-24 08:17 +0000
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
28from __future__ import annotations
30__all__ = ("DimensionRecordQueryResults",)
32from collections.abc import Iterator
33from typing import Any, final
35from ..dimensions import (
36 DimensionElement,
37 DimensionGroup,
38 DimensionRecord,
39 DimensionRecordSet,
40 DimensionRecordTable,
41)
42from ._base import QueryResultsBase
43from .driver import QueryDriver
44from .result_specs import DimensionRecordResultSpec
45from .tree import QueryTree
48@final
49class DimensionRecordQueryResults(QueryResultsBase):
50 """A query for `DimensionRecord` results.
52 Parameters
53 ----------
54 driver : `QueryDriver`
55 Implementation object that knows how to actually execute queries.
56 tree : `QueryTree`
57 Description of the query as a tree of joins and column expressions.
58 The instance returned directly by the `Butler._query` entry point
59 should be constructed via `make_unit_query_tree`.
60 spec : `DimensionRecordResultSpec`
61 Specification of the query result rows, including output columns,
62 ordering, and slicing.
64 Notes
65 -----
66 This class should never be constructed directly by users; use
67 `Query.dimension_records` instead.
68 """
70 def __init__(self, driver: QueryDriver, tree: QueryTree, spec: DimensionRecordResultSpec):
71 spec.validate_tree(tree)
72 super().__init__(driver, tree)
73 self._spec = spec
75 def __iter__(self) -> Iterator[DimensionRecord]:
76 for page in self._driver.execute(self._spec, self._tree):
77 yield from page.rows
79 def iter_table_pages(self) -> Iterator[DimensionRecordTable]:
80 """Return an iterator over individual pages of results as table-backed
81 collections.
83 Yields
84 ------
85 table : `DimensionRecordTable`
86 A table-backed collection of dimension records.
87 """
88 for page in self._driver.execute(self._spec, self._tree):
89 yield page.as_table()
91 def iter_set_pages(self) -> Iterator[DimensionRecordSet]:
92 """Return an iterator over individual pages of results as set-backed
93 collections.
95 Yields
96 ------
97 table : `DimensionRecordSet`
98 A set-backed collection of dimension records.
99 """
100 for page in self._driver.execute(self._spec, self._tree):
101 yield page.as_set()
103 @property
104 def element(self) -> DimensionElement:
105 # Docstring inherited.
106 return self._spec.element
108 @property
109 def dimensions(self) -> DimensionGroup:
110 # Docstring inherited
111 return self._spec.dimensions
113 def count(self, *, exact: bool = True, discard: bool = False) -> int:
114 # Docstring inherited.
115 return self._driver.count(self._tree, self._spec, exact=exact, discard=discard)
117 def _copy(self, tree: QueryTree, **kwargs: Any) -> DimensionRecordQueryResults:
118 # Docstring inherited.
119 return DimensionRecordQueryResults(self._driver, tree, self._spec.model_copy(update=kwargs))
121 def _get_datasets(self) -> frozenset[str]:
122 # Docstring inherited.
123 return frozenset()