GovernorDimensionRecordStorage¶
- class lsst.daf.butler.registry.interfaces.GovernorDimensionRecordStorage¶
Bases:
DimensionRecordStorage
Intermediate interface for
DimensionRecordStorage
objects that provide storage forGovernorDimension
instances.Attributes Summary
The element whose records this instance holds (
DimensionElement
).The SQLAlchemy table that backs this dimension (
sqlalchemy.schema.Table
).Methods Summary
Clear any in-memory caches held by the storage instance.
Return tables used for schema digest.
fetch
(dataIds)Retrieve records from storage.
initialize
(db, dimension, *[, context])Construct an instance of this class using a standardized interface.
insert
(*records[, replace])Insert one or more records into storage.
join
(builder, *[, regions, timespans])Add the dimension element's logical table to a query under construction.
refresh
()Ensure all other operations on this manager are aware of any changes made by other clients since it was initialized or last refreshed.
registerInsertionListener
(callback)Add a function or method to be called after new records for this dimension are inserted by
insert
orsync
.sync
(record[, update])Synchronize a record with the database, inserting it only if it does not exist and comparing values if it does.
Attributes Documentation
- element¶
- table¶
The SQLAlchemy table that backs this dimension (
sqlalchemy.schema.Table
).
- values¶
All primary key values for this dimension (
set
[str
]).This may rely on an in-memory cache and hence not reflect changes to the set of values made by other
Butler
/Registry
clients. Callrefresh
to ensure up-to-date results.
Methods Documentation
- abstract clearCaches() None ¶
Clear any in-memory caches held by the storage instance.
This is called by
Registry
when transactions are rolled back, to avoid in-memory caches from ever containing records that are not present in persistent storage.
- abstract digestTables() Iterable[Table] ¶
Return tables used for schema digest.
- Returns:
- tables
Iterable
[sqlalchemy.schema.Table
] Possibly empty set of tables for schema digest calculations.
- tables
- abstract fetch(dataIds: DataCoordinateIterable) Iterable[DimensionRecord] ¶
Retrieve records from storage.
- Parameters:
- dataIds
DataCoordinateIterable
Data IDs that identify the records to be retrieved.
- dataIds
- Returns:
- records
Iterable
[DimensionRecord
] Record retrieved from storage. Not all data IDs may have corresponding records (if there are no records that match a data ID), and even if they are, the order of inputs is not preserved.
- records
- abstract classmethod initialize(db: Database, dimension: GovernorDimension, *, context: Optional[StaticTablesContext] = None, config: Mapping[str, Any]) GovernorDimensionRecordStorage ¶
Construct an instance of this class using a standardized interface.
- Parameters:
- db
Database
Interface to the underlying database engine and namespace.
- dimension
GovernorDimension
Dimension the new instance will manage records for.
- context
StaticTablesContext
, optional If provided, an object to use to create any new tables. If not provided,
db.ensureTableExists
should be used instead.- config
Mapping
Extra configuration options specific to the implementation.
- db
- Returns:
- storage
GovernorDimensionRecordStorage
A new
GovernorDimensionRecordStorage
subclass instance.
- storage
- abstract insert(*records: DimensionRecord, replace: bool = False) None ¶
Insert one or more records into storage.
- Parameters:
- Raises:
- TypeError
Raised if the element does not support record insertion.
- sqlalchemy.exc.IntegrityError
Raised if one or more records violate database integrity constraints.
Notes
As
insert
is expected to be called only by aRegistry
, we rely onRegistry
to provide transactionality, both by using a SQLALchemy connection shared with theRegistry
and by relying on it to callclearCaches
when rolling back transactions.
- abstract join(builder: QueryBuilder, *, regions: Optional[NamedKeyDict[DimensionElement, sqlalchemy.sql.ColumnElement]] = None, timespans: Optional[NamedKeyDict[DimensionElement, TimespanDatabaseRepresentation]] = None) sqlalchemy.sql.FromClause ¶
Add the dimension element’s logical table to a query under construction.
This is a visitor pattern interface that is expected to be called only by
QueryBuilder.joinDimensionElement
.- Parameters:
- builder
QueryBuilder
Builder for the query that should contain this element.
- regions
NamedKeyDict
, optional A mapping from
DimensionElement
to a SQLAlchemy column containing the region for that element, which should be updated to include a region column for this element if one exists. IfNone
,self.element
is not being included in the query via a spatial join.- timespan
NamedKeyDict
, optional A mapping from
DimensionElement
to aTimespan
of SQLALchemy columns containing the timespan for that element, which should be updated to include timespan columns for this element if they exist. IfNone
,self.element
is not being included in the query via a temporal join.
- builder
- Returns:
- fromClause
sqlalchemy.sql.FromClause
Table or clause for the element which is joined.
- fromClause
Notes
Elements are only included in queries via spatial and/or temporal joins when necessary to connect them to other elements in the query, so
regions
andtimespans
cannot be assumed to be notNone
just because an element has a region or timespan.
- abstract refresh() None ¶
Ensure all other operations on this manager are aware of any changes made by other clients since it was initialized or last refreshed.
- abstract registerInsertionListener(callback: Callable[[DimensionRecord], None]) None ¶
Add a function or method to be called after new records for this dimension are inserted by
insert
orsync
.- Parameters:
- callback
Callable that takes a single
DimensionRecord
argument. This will be called immediately after any successful insertion, in the same transaction.
- abstract sync(record: DimensionRecord, update: bool = False) Union[bool, Dict[str, Any]] ¶
Synchronize a record with the database, inserting it only if it does not exist and comparing values if it does.
- Parameters:
- Returns:
- Raises:
- DatabaseConflictError
Raised if the record exists in the database (according to primary key lookup) but is inconsistent with the given one.
- TypeError
Raised if the element does not support record synchronization.
- sqlalchemy.exc.IntegrityError
Raised if one or more records violate database integrity constraints.