DimensionRecordStorageManager¶
- class lsst.daf.butler.registry.interfaces.DimensionRecordStorageManager(*, universe: DimensionUniverse, registry_schema_version: VersionTuple | None = None)¶
Bases:
VersionedExtensionAn interface for managing the dimension records in a
Registry.DimensionRecordStorageManagerprimarily serves as a container and factory forDimensionRecordStorageinstances, which each provide access to the records for a differentDimensionElement.- Parameters:
- universe
DimensionUniverse Universe of all dimensions and dimension elements known to the
Registry.- registry_schema_version
VersionTupleorNone, optional Version of registry schema.
- universe
Notes
In a multi-layer
Registry, many dimension elements will only have records in one layer (often the base layer). The union of the records across all layers forms the logical table for the fullRegistry.Methods Summary
clone(db)Make an independent copy of this manager instance bound to a new
Databaseinstance.Return a
dictthat can back aDimensionRecordSet.fetch_one(element_name, data_id, cache)Retrieve a single record from storage.
initialize(db, context, *, universe[, ...])Construct an instance of the manager.
insert(element, *records[, replace, ...])Insert one or more records into storage.
join(element_name, target, join, context)Join this dimension element's records to a relation.
load_dimension_group(key)Retrieve a
DimensionGroupthat was previously saved in the database.make_joins_builder(element, fields)Make a
direct_query_driver.SqlJoinsBuilderthat represents a dimension element table.process_query_overlaps(dimensions, ...)Process a query's WHERE predicate and dimensions to handle spatial and temporal overlaps.
save_dimension_group(group)Save a
DimensionGroupdefinition to the database, allowing it to be retrieved later via the returned key.sync(record[, update])Synchronize a record with the database, inserting it only if it does not exist and comparing values if it does.
Methods Documentation
- abstract clone(db: Database) DimensionRecordStorageManager¶
Make an independent copy of this manager instance bound to a new
Databaseinstance.- Parameters:
- Returns:
- instance
DatasetRecordStorageManager New manager instance with the same configuration as this instance, but bound to a new Database object.
- instance
- fetch_cache_dict() dict[str, lsst.daf.butler.dimensions._record_set.DimensionRecordSet]¶
Return a
dictthat can back aDimensionRecordSet.This method is intended as the
fetchcallback argument toDimensionRecordCache, in contexts where direct SQL queries are possible.
- abstract fetch_one(element_name: str, data_id: DataCoordinate, cache: DimensionRecordCache) DimensionRecord | None¶
Retrieve a single record from storage.
- Parameters:
- element_name
str Name of the dimension element for the record to fetch.
- data_id
DataCoordinate Data ID of the record to fetch. Implied dimensions do not need to be present.
- cache
DimensionRecordCache Cache to look in first.
- element_name
- Returns:
- abstract classmethod initialize(db: Database, context: StaticTablesContext, *, universe: DimensionUniverse, registry_schema_version: VersionTuple | None = None) DimensionRecordStorageManager¶
Construct an instance of the manager.
- Parameters:
- db
Database Interface to the underlying database engine and namespace.
- context
StaticTablesContext Context object obtained from
Database.declareStaticTables; used to declare any tables that should always be present in a layer implemented with this manager.- universe
DimensionUniverse Universe graph containing dimensions known to this
Registry.- registry_schema_version
VersionTupleorNone Schema version of this extension as defined in registry.
- db
- Returns:
- manager
DimensionRecordStorageManager An instance of a concrete
DimensionRecordStorageManagersubclass.
- manager
- abstract insert(element: DimensionElement, *records: DimensionRecord, replace: bool = False, skip_existing: bool = False) None¶
Insert one or more records into storage.
- Parameters:
- element
DimensionElement Dimension element that provides the definition for records.
- *records
DimensionRecord One or more instances of the
DimensionRecordsubclass for the element this storage is associated with.- replace
bool, optional If
True(Falseis default), replace existing records in the database if there is a conflict.- skip_existing
bool, optional If
True(Falseis default), skip insertion if a record with the same primary key values already exists.
- element
- Raises:
- TypeError
Raised if the element does not support record insertion.
- sqlalchemy.exc.IntegrityError
Raised if one or more records violate database integrity constraints.
- abstract join(element_name: str, target: Relation, join: Join, context: queries.SqlQueryContext) Relation¶
Join this dimension element’s records to a relation.
- Parameters:
- element_name
str Name of the dimension element whose relation should be joined in.
- target
Relation Existing relation to join to. Implementations may require that this relation already include dimension key columns for this dimension element and assume that dataset or spatial join relations that might provide these will be included in the relation tree first.
- join
Join Join operation to use when the implementation is an actual join. When a true join is being simulated by other relation operations, this objects
min_columnsandmax_columnsshould still be respected.- context
queries.SqlQueryContext Object that manages relation engines and database-side state (e.g. temporary tables) for the query.
- element_name
- Returns:
- joined
Relation New relation that includes this relation’s dimension key and record columns, as well as all columns in
target, with rows constrained to those for which this element’s dimension key values exist in the registry and rows already exist intarget.
- joined
- abstract load_dimension_group(key: int) DimensionGroup¶
Retrieve a
DimensionGroupthat was previously saved in the database.- Parameters:
- key
int Integer used as the unique key for this
DimensionGroupin the database.
- key
- Returns:
- dimensions
DimensionGroup Retrieved dimensions.
- dimensions
- Raises:
- KeyError
Raised if the given key cannot be found in the database.
- abstract make_joins_builder(element: DimensionElement, fields: Set[str]) SqlJoinsBuilder¶
Make a
direct_query_driver.SqlJoinsBuilderthat represents a dimension element table.- Parameters:
- element
DimensionElement Dimension element the table corresponds to.
- fields
Set[str] Names of fields to make available in the builder. These can be any metadata or alternate key field in the element’s schema, including the special
regionandtimespanfields. Dimension keys in the element’s schema are always included.
- element
- Returns:
- builder
direct_query_driver.SqlJoinsBuilder A query-construction object representing a table or subquery. This is guaranteed to have rows that are unique over dimension keys and all possible key values for this dimension, so joining in a dimension element table:
never introduces duplicates into the query’s result rows;
never restricts the query’s rows except to ensure required-implied relationships are followed.
- builder
- abstract process_query_overlaps(dimensions: DimensionGroup, predicate: Predicate, join_operands: Iterable[DimensionGroup], calibration_dataset_types: Set[str | AnyDatasetType], allow_duplicates: bool, constraint_data_id: Mapping[str, DataIdValue]) tuple[Predicate, SqlSelectBuilder, Postprocessing]¶
Process a query’s WHERE predicate and dimensions to handle spatial and temporal overlaps.
- Parameters:
- dimensions
dimensions.DimensionGroup Full dimensions of all tables to be joined into the query (even if they are not included in the query results).
- predicate
queries.tree.Predicate Boolean column expression that may contain user-provided spatial and/or temporal overlaps intermixed with other constraints.
- join_operands
Iterable[dimensions.DimensionGroup] Dimensions of tables or subqueries that are already going to be joined into the query that may establish their own spatial or temporal relationships (e.g. a dataset search with both
visitandpatchdimensions).- calibration_dataset_types
Set[strorqueries.tree.AnyDatasetType] The names of dataset types that have been joined into the query via a search that includes at least one calibration collection.
- allow_duplicates
bool If set to
Truethen query will be allowed to return non-distinct rows.- constraint_data_id
Mapping[str,int|str] Dimension values that are known to be common to all rows in the query result set.
- dimensions
- Returns:
- predicate
queries.tree.Predicate A version of the given predicate that preserves the overall behavior of the filter while possibly rewriting overlap expressions that have been partially moved into
builderas some combination of new nested predicates, joins, and postprocessing.- builder
direct_query_driver.SqlSelectBuilder A query-construction helper object that includes any initial joins and postprocessing needed to handle overlap expression extracted from the original predicate.
- postprocessing
Postprocessing Struct representing post-query processing to be done in Python.
- predicate
Notes
Implementations must delegate to
queries.overlaps.OverlapsVisitor(possibly by subclassing it) to ensure “automatic” spatial and temporal joins are added consistently by all query-construction implementations.
- abstract save_dimension_group(group: DimensionGroup) int¶
Save a
DimensionGroupdefinition to the database, allowing it to be retrieved later via the returned key.If this dimension group has already been saved, this method just returns the key already associated with it.
- Parameters:
- group
DimensionGroup Set of dimensions to save.
- group
- Returns:
- key
int Integer used as the unique key for this
DimensionGroupin the database.
- key
- Raises:
- TransactionInterruption
Raised if this operation is invoked within a
Database.transactioncontext.
- abstract sync(record: DimensionRecord, update: bool = False) 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.