Coverage for python/lsst/daf/butler/registry/dimensions/query.py : 78%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# 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 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/>.
"""A read-only record storage implementation backed by SELECT query.
At present, the only query this class supports is a SELECT DISTNCT over the table for some other dimension that has this dimension as an implied dependency. For example, we can use this class to provide access to the set of ``abstract_filter`` names referenced by any ``physical_filter``.
Parameters ---------- db : `Database` Interface to the database engine and namespace that will hold these dimension records. element : `DimensionElement` The element whose records this storage will manage. """ raise NotImplementedError("Query-backed dimension must be a dependency of its target.") raise NotImplementedError("Cannot use query to back dimension with metadata.") raise NotImplementedError("Cannot use query to back dimension with implied dependencies.") raise NotImplementedError("Cannot use query to back dimension with alternate unique keys.") raise NotImplementedError("Cannot use query to back spatial dimension.") raise NotImplementedError("Cannot use query to back temporal dimension.")
context: Optional[StaticTablesContext] = None) -> DimensionRecordStorage: # Docstring inherited from DimensionRecordStorage.
def element(self) -> DimensionElement: # Docstring inherited from DimensionRecordStorage.element.
# Docstring inherited from DimensionRecordStorage.clearCaches.
# The only columns for this dimension are ones for its required # dependencies and its own primary key (guaranteed by the checks in # the ctor). else: columns.append(targetTable.columns[dimension.name].label(dimension.name)) # This query doesn't do a SELECT DISTINCT, because that's confusing # and potentially wasteful if we apply a restrictive WHERE clause, # as SelectableDimensionRecordStorage.fetch will do. # Instead, we add DISTINCT in join() only. columns, distinct=True ).select_from( targetTable ).alias( self.element.name )
self, builder: QueryBuilder, *, regions: Optional[NamedKeyDict[DimensionElement, sqlalchemy.sql.ColumnElement]] = None, timespans: Optional[NamedKeyDict[DimensionElement, Timespan[sqlalchemy.sql.ColumnElement]]] = None, ): # Docstring inherited from DimensionRecordStorage. # Do nothing; the target dimension is already being included, so # joining against a subquery referencing it would just produce a # more complicated query that's guaranteed to return the same # results. return self.element.RecordClass.__slots__)
# Docstring inherited from DimensionRecordStorage.insert.
# Docstring inherited from DimensionRecordStorage.fetch. # Given the restrictions imposed at construction, we know there's # nothing to actually fetch: everything we need is in the data ID. |