From d6fd3fb8c24b5ff5304ffc2c4f87815f4861b9ef Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Wed, 27 Dec 2023 16:27:02 -0500 Subject: [PATCH] Add table property to DimensionRecordStorage. --- .../daf/butler/registry/dimensions/caching.py | 5 +++++ .../daf/butler/registry/dimensions/governor.py | 3 ++- .../daf/butler/registry/dimensions/query.py | 5 +++++ .../daf/butler/registry/dimensions/skypix.py | 5 +++++ .../daf/butler/registry/dimensions/table.py | 5 +++++ .../butler/registry/interfaces/_dimensions.py | 18 ++++++++++-------- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/python/lsst/daf/butler/registry/dimensions/caching.py b/python/lsst/daf/butler/registry/dimensions/caching.py index 08cc829995..ff341ce1f6 100644 --- a/python/lsst/daf/butler/registry/dimensions/caching.py +++ b/python/lsst/daf/butler/registry/dimensions/caching.py @@ -109,6 +109,11 @@ def element(self) -> DatabaseDimensionElement: # Docstring inherited from DimensionRecordStorage.element. return self._nested.element + @property + def table(self) -> sqlalchemy.Table: + # Docstring inherited from DimensionRecordStorage. + return self._nested.table + def clearCaches(self) -> None: # Docstring inherited from DimensionRecordStorage.clearCaches. self._cache = None diff --git a/python/lsst/daf/butler/registry/dimensions/governor.py b/python/lsst/daf/butler/registry/dimensions/governor.py index 535e0ced44..87b997ee0f 100644 --- a/python/lsst/daf/butler/registry/dimensions/governor.py +++ b/python/lsst/daf/butler/registry/dimensions/governor.py @@ -95,7 +95,8 @@ def element(self) -> GovernorDimension: return self._dimension @property - def table(self) -> sqlalchemy.schema.Table: + def table(self) -> sqlalchemy.Table: + # Docstring inherited from DimensionRecordStorage. return self._table def registerInsertionListener(self, callback: Callable[[DimensionRecord], None]) -> None: diff --git a/python/lsst/daf/butler/registry/dimensions/query.py b/python/lsst/daf/butler/registry/dimensions/query.py index ef39bff6ea..e18eaa02d8 100644 --- a/python/lsst/daf/butler/registry/dimensions/query.py +++ b/python/lsst/daf/butler/registry/dimensions/query.py @@ -115,6 +115,11 @@ def element(self) -> DatabaseDimension: # Docstring inherited from DimensionRecordStorage.element. return self._element + @property + def table(self) -> sqlalchemy.Table: + # Docstring inherited from DimensionRecordStorage. + return self._target.table + def clearCaches(self) -> None: # Docstring inherited from DimensionRecordStorage.clearCaches. pass diff --git a/python/lsst/daf/butler/registry/dimensions/skypix.py b/python/lsst/daf/butler/registry/dimensions/skypix.py index 6d8a03fe41..b42c734784 100644 --- a/python/lsst/daf/butler/registry/dimensions/skypix.py +++ b/python/lsst/daf/butler/registry/dimensions/skypix.py @@ -61,6 +61,11 @@ def element(self) -> SkyPixDimension: # Docstring inherited from DimensionRecordStorage.element. return self._dimension + @property + def table(self) -> sqlalchemy.Table: + # Docstring inherited from DimensionRecordStorage. + raise AssertionError("SkyPix dimensions do not have SQL tables.") + def clearCaches(self) -> None: # Docstring inherited from DimensionRecordStorage.clearCaches. pass diff --git a/python/lsst/daf/butler/registry/dimensions/table.py b/python/lsst/daf/butler/registry/dimensions/table.py index 250a959643..dd3a9e6f32 100644 --- a/python/lsst/daf/butler/registry/dimensions/table.py +++ b/python/lsst/daf/butler/registry/dimensions/table.py @@ -143,6 +143,11 @@ def element(self) -> DatabaseDimensionElement: # Docstring inherited from DimensionRecordStorage.element. return self._element + @property + def table(self) -> sqlalchemy.Table: + # Docstring inherited from DimensionRecordStorage. + return self._table + def clearCaches(self) -> None: # Docstring inherited from DimensionRecordStorage.clearCaches. pass diff --git a/python/lsst/daf/butler/registry/interfaces/_dimensions.py b/python/lsst/daf/butler/registry/interfaces/_dimensions.py index 189517bb25..0f4de3f6d6 100644 --- a/python/lsst/daf/butler/registry/interfaces/_dimensions.py +++ b/python/lsst/daf/butler/registry/interfaces/_dimensions.py @@ -133,6 +133,16 @@ def join( """ raise NotImplementedError() + @property + @abstractmethod + def table(self) -> sqlalchemy.Table: + """The SQLAlchemy table that holds this elements records. + + This property should raise when accessed if + `DimensionElement.hasTable` is not `True`. + """ + raise NotImplementedError() + @abstractmethod def insert(self, *records: DimensionRecord, replace: bool = False, skip_existing: bool = False) -> None: """Insert one or more records into storage. @@ -332,14 +342,6 @@ def element(self) -> GovernorDimension: # Docstring inherited from DimensionRecordStorage. raise NotImplementedError() - @property - @abstractmethod - def table(self) -> sqlalchemy.schema.Table: - """The SQLAlchemy table that backs this dimension - (`sqlalchemy.schema.Table`). - """ - raise NotImplementedError() - def join( self, target: Relation,