-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-46129: Make collections.query_info a single HTTP call #1074
Changes from 7 commits
bcf3cd2
063d572
694d360
a7ea9f2
56d6a27
8c3ca9c
701bd48
af34091
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -796,3 +796,21 @@ | |
arguments as well as positional arguments. | ||
""" | ||
return factory(*args, **kwargs) | ||
|
||
|
||
def get_dataset_type_name(datasetTypeOrName: DatasetType | str) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make it a classmethod of |
||
"""Given a `DatasetType` object or a dataset type name, return a dataset | ||
type name. | ||
|
||
Parameters | ||
---------- | ||
datasetTypeOrName : `DatasetType` | `str` | ||
A DatasetType, or the name of a DatasetType. This union is a common | ||
parameter in many `Butler` methods. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstring also needs |
||
if isinstance(datasetTypeOrName, DatasetType): | ||
return datasetTypeOrName.name | ||
elif isinstance(datasetTypeOrName, str): | ||
return datasetTypeOrName | ||
else: | ||
raise TypeError(f"Expected DatasetType or str, got unexpected object: {datasetTypeOrName}") | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import sqlalchemy | ||
|
||
from ...._dataset_ref import DatasetId, DatasetIdGenEnum, DatasetRef, DatasetType | ||
from ...._dataset_type import get_dataset_type_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
from ...._exceptions_legacy import DatasetTypeError | ||
from ....dimensions import DimensionUniverse | ||
from ..._collection_summary import CollectionSummary | ||
|
@@ -511,12 +512,14 @@ def getCollectionSummary(self, collection: CollectionRecord) -> CollectionSummar | |
return summaries[collection.key] | ||
|
||
def fetch_summaries( | ||
self, collections: Iterable[CollectionRecord], dataset_types: Iterable[DatasetType] | None = None | ||
self, | ||
collections: Iterable[CollectionRecord], | ||
dataset_types: Iterable[DatasetType] | Iterable[str] | None = None, | ||
) -> Mapping[Any, CollectionSummary]: | ||
# Docstring inherited from DatasetRecordStorageManager. | ||
dataset_type_names: Iterable[str] | None = None | ||
if dataset_types is not None: | ||
dataset_type_names = set(dataset_type.name for dataset_type in dataset_types) | ||
dataset_type_names = set(get_dataset_type_name(dt) for dt in dataset_types) | ||
return self._summaries.fetch_summaries(collections, dataset_type_names, self._dataset_type_from_row) | ||
|
||
_versions: list[VersionTuple] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This file is part of daf_butler. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (http://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This software is dual licensed under the GNU General Public License and also | ||
# under a 3-clause BSD license. Recipients may choose which of these licenses | ||
# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, | ||
# respectively. If you choose the GPL option then the following text applies | ||
# (but note that there is still no warranty even if you opt for BSD instead): | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from ..registry import RegistryDefaults | ||
|
||
|
||
class DefaultsHolder: | ||
"""Holds a `RegistryDefaults` object and allows it to be set. | ||
|
||
Parameters | ||
---------- | ||
defaults : `RegistryDefaults` | ||
Initial value for the defaults object. | ||
|
||
Notes | ||
----- | ||
This exists to work around circular dependency issues (RemoteButler, | ||
ButlerCollections, and Registry all need to know/modify the defaults.) | ||
""" | ||
|
||
def __init__(self, defaults: RegistryDefaults) -> None: | ||
self._defaults = defaults | ||
|
||
def get(self) -> RegistryDefaults: | ||
"""Retrieve the current registry defaults.""" | ||
return self._defaults | ||
|
||
def set(self, defaults: RegistryDefaults) -> None: | ||
"""Set a new value for the registry defaults. | ||
|
||
Parameters | ||
---------- | ||
defaults : `RegistryDefaults` | ||
New value for defaults object. | ||
""" | ||
self._defaults = defaults |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we allow
Iterable[str]
only to avoid all complications? I think that clients of this method that actually passsummary_datasets
should already have a list of names for other purposes. I guess this also means that datasets manager has to acceptIterable[str]
instead ofIterable[DatasetType]
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same thing, but the convention in the rest of the new query system is that dataset types can be specified as either the name or
DatasetType
instance so it makes sense to follow that. It's also common for this parameter to come from the result of a queryDatasetTypes call.