DimensionRecordStorageManager¶
- class lsst.daf.butler.registry.interfaces.DimensionRecordStorageManager(*, universe: DimensionUniverse, registry_schema_version: VersionTuple | None = None)¶
- Bases: - VersionedExtension- An interface for managing the dimension records in a - Registry.- DimensionRecordStorageManagerprimarily serves as a container and factory for- DimensionRecordStorageinstances, which each provide access to the records for a different- DimensionElement.- Parameters:
- universeDimensionUniverse
- Universe of all dimensions and dimension elements known to the - Registry.
- registry_schema_versionVersionTupleorNone, 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 full- Registry.- Methods Summary - checkCompatibility(registry_schema_version, ...)- Check that schema version defined in registry is compatible with current implementation. - checkNewSchemaVersion(schema_version)- Verify that requested schema version can be created by an extension. - clone(db)- Make an independent copy of this manager instance bound to a new - Databaseinstance.- clsNewSchemaVersion(schema_version)- Class method which returns schema version to use for newly created registry database. - Return schema version(s) supported by this extension class. - Return full name of the extension. - Return a - dictthat can back a- DimensionRecordSet.- 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_spatial_join_relation(element1, ...[, ...])- Create a relation that represents the spatial join between two dimension elements. - Return schema version for newly created registry. - 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 - classmethod checkCompatibility(registry_schema_version: VersionTuple, update: bool) None¶
- Check that schema version defined in registry is compatible with current implementation. - Parameters:
- registry_schema_versionVersionTuple
- Schema version that exists in registry or defined in a configuration for a registry to be created. 
- updatebool
- If True then read-write access is expected. 
 
- registry_schema_version
- Raises:
- IncompatibleVersionError
- Raised if schema version is not supported by implementation. 
 
 - Notes - Default implementation uses - VersionTuple.checkCompatibilityon the versions returned from- currentVersionsmethod. Subclasses that support different compatibility model will overwrite this method.
 - classmethod checkNewSchemaVersion(schema_version: VersionTuple) None¶
- Verify that requested schema version can be created by an extension. - Parameters:
- schema_versionVersionTuple
- Schema version that this extension is asked to create. 
 
- schema_version
 - Notes - This method may be used only occasionally when a specific schema version is given in a regisitry config file. This can be used with an extension that supports multiple schem versions to make it create new schema with a non-default version number. Default implementation compares requested version with one of the version returned from - currentVersions.
 - abstract clone(db: Database) DimensionRecordStorageManager¶
- Make an independent copy of this manager instance bound to a new - Databaseinstance.- Parameters:
- Returns:
- instanceDatasetRecordStorageManager
- New manager instance with the same configuration as this instance, but bound to a new Database object. 
 
- instance
 
 - classmethod clsNewSchemaVersion(schema_version: VersionTuple | None) VersionTuple | None¶
- Class method which returns schema version to use for newly created registry database. - Parameters:
- schema_versionVersionTupleorNone
- Configured schema version or - Noneif default schema version should be created. If not- Nonethen it is guaranteed to be compatible with- currentVersions.
 
- schema_version
- Returns:
- versionVersionTupleorNone
- Schema version created by this extension. - Noneis returned if an extension does not require its version to be saved or checked.
 
- version
 - Notes - Default implementation of this method can work in simple cases. If the extension only supports single schema version than that version is returned. If the extension supports multiple schema versions and - schema_versionis not- Nonethen- schema_versionis returned. If the extension supports multiple schema versions, but- schema_versionis- Noneit calls- _newDefaultSchemaVersionmethod which needs to be reimplemented in a subsclass.
 - abstract classmethod currentVersions() list[lsst.daf.butler.registry.interfaces._versioning.VersionTuple]¶
- Return schema version(s) supported by this extension class. - Returns:
- versionlist[VersionTuple]
- Schema versions for this extension. Empty list is returned if an extension does not require its version to be saved or checked. 
 
- version
 
 - classmethod extensionName() str¶
- Return full name of the extension. - This name should match the name defined in registry configuration. It is also stored in registry attributes. Default implementation returns full class name. - Returns:
- namestr
- Full extension name. 
 
- name
 
 - fetch_cache_dict() dict[str, lsst.daf.butler.dimensions._record_set.DimensionRecordSet]¶
- Return a - dictthat can back a- DimensionRecordSet.- This method is intended as the - fetchcallback argument to- DimensionRecordCache, 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_namestr
- Name of the dimension element for the record to fetch. 
- data_idDataCoordinate
- Data ID of the record to fetch. Implied dimensions do not need to be present. 
- cacheDimensionRecordCache
- 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:
- dbDatabase
- Interface to the underlying database engine and namespace. 
- contextStaticTablesContext
- Context object obtained from - Database.declareStaticTables; used to declare any tables that should always be present in a layer implemented with this manager.
- universeDimensionUniverse
- Universe graph containing dimensions known to this - Registry.
- registry_schema_versionVersionTupleorNone
- Schema version of this extension as defined in registry. 
 
- db
- Returns:
- managerDimensionRecordStorageManager
- 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:
- elementDimensionElement
- Dimension element that provides the definition for records. 
- *recordsDimensionRecord
- One or more instances of the - DimensionRecordsubclass for the element this storage is associated with.
- replacebool, optional
- If - True(- Falseis default), replace existing records in the database if there is a conflict.
- skip_existingbool, 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_namestr
- Name of the dimension element whose relation should be joined in. 
- targetRelation
- 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. 
- joinJoin
- 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_columnsand- max_columnsshould still be respected.
- contextqueries.SqlQueryContext
- Object that manages relation engines and database-side state (e.g. temporary tables) for the query. 
 
- element_name
- Returns:
- joinedRelation
- 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 in- target.
 
- joined
 
 - abstract load_dimension_group(key: int) DimensionGroup¶
- Retrieve a - DimensionGroupthat was previously saved in the database.- Parameters:
- keyint
- Integer used as the unique key for this - DimensionGroupin the database.
 
- key
- Returns:
- dimensionsDimensionGroup
- Retrieved dimensions. 
 
- dimensions
- Raises:
- KeyError
- Raised if the given key cannot be found in the database. 
 
 
 - abstract make_spatial_join_relation(element1: str, element2: str, context: queries.SqlQueryContext, existing_relationships: Set[frozenset[str]] = frozenset({})) tuple[Relation, bool]¶
- Create a relation that represents the spatial join between two dimension elements. - Parameters:
- element1str
- Name of one of the elements participating in the join. 
- element2str
- Name of the other element participating in the join. 
- contextqueries.SqlQueryContext
- Object that manages relation engines and database-side state (e.g. temporary tables) for the query. 
- existing_relationshipsSet[frozenset[str] ], optional
- Relationships between dimensions that are already present in the relation the result will be joined to. Spatial join relations that duplicate these relationships will not be included in the result, which may cause an identity relation to be returned if a spatial relationship has already been established. 
 
- element1
- Returns:
- relationlsst.daf.relation.Relation
- New relation that represents a spatial join between the two given elements. Guaranteed to have key columns for all required dimensions of both elements. 
- needs_refinementbool
- Whether the returned relation represents a conservative join that needs refinement via native-iteration predicate. 
 
- relation
 
 - newSchemaVersion() VersionTuple | None¶
- Return schema version for newly created registry. - Returns:
- versionVersionTupleorNone
- Schema version created by this extension. - Noneis returned if an extension does not require its version to be saved or checked.
 
- version
 - Notes - Extension classes that support multiple schema versions need to override - _newDefaultSchemaVersionmethod.
 - abstract save_dimension_group(group: DimensionGroup) int¶
- Save a - DimensionGroupdefinition to the database, allowing it to be retrieved later via the returned key.- Parameters:
- groupDimensionGroup
- Set of dimensions to save. 
 
- group
- Returns:
- keyint
- 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.