Coverage for python/lsst/daf/butler/registry/tables.py : 64%

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
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software=you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21from __future__ import annotations
23__all__ = ["RegistryTablesTuple", "makeRegistryTableSpecs"]
25from collections import namedtuple
26from typing import Type
28import sqlalchemy
30from ..core import (
31 ddl,
32 DimensionUniverse,
33)
34from .interfaces import CollectionManager, DatasetRecordStorageManager
37RegistryTablesTuple = namedtuple(
38 "RegistryTablesTuple",
39 [
40 "quantum",
41 "dataset_consumers",
42 ]
43)
46def makeRegistryTableSpecs(universe: DimensionUniverse,
47 collections: Type[CollectionManager],
48 datasets: Type[DatasetRecordStorageManager],
49 ) -> RegistryTablesTuple:
50 """Construct descriptions tables in the Registry that are not (yet)
51 managed by helper classes.
53 Parameters
54 ----------
55 universe : `DimensionUniverse`
56 All dimensions known to the `Registry`.
57 collections : `Collection`
58 The `CollectionManager` that will be used for this `Registry`; used to
59 create foreign keys to the run and collection tables.
60 datasets : subclass of `DatasetRecordStorageManager`
61 Manager class for dataset tables; used only to create foreign keys.
63 Returns
64 -------
65 specs : `RegistryTablesTuple`
66 A named tuple containing `ddl.TableSpec` instances.
67 """
68 quantum = ddl.TableSpec(
69 doc="A table used to capture fine-grained provenance for datasets produced by PipelineTasks.",
70 fields=[
71 ddl.FieldSpec(
72 name="id",
73 dtype=sqlalchemy.BigInteger,
74 primaryKey=True,
75 autoincrement=True,
76 doc="A unique autoincrement integer identifier for this quantum.",
77 ),
78 ddl.FieldSpec(
79 name="task",
80 dtype=sqlalchemy.String,
81 length=256,
82 doc="Fully qualified name of the SuperTask that executed this quantum.",
83 ),
84 ddl.FieldSpec(
85 name="start_time",
86 dtype=ddl.AstropyTimeNsecTai,
87 nullable=True,
88 doc="The start time for the quantum.",
89 ),
90 ddl.FieldSpec(
91 name="end_time",
92 dtype=ddl.AstropyTimeNsecTai,
93 nullable=True,
94 doc="The end time for the quantum.",
95 ),
96 ddl.FieldSpec(
97 name="host",
98 dtype=sqlalchemy.String,
99 length=64,
100 nullable=True,
101 doc="The system on which the quantum was executed.",
102 ),
103 ],
104 )
105 collections.addRunForeignKey(quantum, onDelete="CASCADE", nullable=False)
107 dataset_consumers = ddl.TableSpec(
108 doc="A table relating Quantum records to the datasets they used as inputs.",
109 fields=[
110 ddl.FieldSpec(
111 name="quantum_id",
112 dtype=sqlalchemy.BigInteger,
113 nullable=False,
114 doc="A link to the associated Quantum.",
115 ),
116 ddl.FieldSpec(
117 name="actual",
118 dtype=sqlalchemy.Boolean,
119 nullable=False,
120 doc=(
121 "Whether the Dataset was actually used as an input by the Quantum "
122 "(as opposed to just predicted to be used during preflight)."
123 ),
124 ),
125 ],
126 foreignKeys=[
127 ddl.ForeignKeySpec(
128 table="quantum",
129 source=("quantum_id",),
130 target=("id",),
131 onDelete="CASCADE",
132 ),
133 ]
134 )
135 datasets.addDatasetForeignKey(dataset_consumers, nullable=True, onDelete="SET NULL")
136 return RegistryTablesTuple(
137 quantum=quantum,
138 dataset_consumers=dataset_consumers,
139 )