Coverage for python/lsst/daf/butler/core/schema.py : 91%

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
# This file is part of daf_butler. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
Float, ForeignKeyConstraint, Table, MetaData
"""The SQL schema for a Butler Registry.
Parameters ---------- config : `SchemaConfig` or `str`, optional Load configuration. Defaults will be read if ``config`` is not a `SchemaConfig`. limited : `bool` If `True`, ignore tables, views, and associated foreign keys whose config descriptions include a "limited" key set to `False`.
Attributes ---------- metadata : `sqlalchemy.MetaData` The sqlalchemy schema description. tables : `dict` A mapping from table or view name to the associated SQLAlchemy object. Note that this contains both true tables and views. views : `frozenset` The names of entries in ``tables`` that are actually implemented as views. """
"""Builds a Schema step-by-step.
Parameters ---------- config : `SchemaConfig` Configuration to parse. limited : `bool` If `True`, ignore tables, views, and associated foreign keys whose config descriptions include a "limited" key set to `False`.
Attributes ---------- metadata : `sqlalchemy.MetaData` The sqlalchemy schema description. tables : `dict` A mapping from table or view name to the associated SQLAlchemy object. Note that this contains both true tables and views. views : `set` The names of all entries in ``tables`` that are actually implemented as views. """ "bool": Boolean, "blob": LargeBinary, "datetime": DateTime}
"""Return True if the named table should be added / has been added as a view.
Parameters ---------- name : `str` Name of a table or view. Does not need to have been added.
Returns ------- view : `bool` Whether the table should be added / has been added as a view. """
"""Return True if the named table or view should be included in this schema.
Parameters ---------- name : `str` Name of a table or view. Does not need to have been added.
Returns ------- included : `bool` Whether the table or view should be included in the schema. """ return False
"""Add a table to the schema metadata.
Parameters ---------- tableName : `str` Key of the table. tableDescription : `dict` Table description.
Requires: - columns, a list of column descriptions - foreignKeys, a list of foreign-key constraint descriptions
Raises ------ ValueError If a table with the given name already exists. """ raise ValueError("Table with name {} already exists".format(tableName)) # Create a Table object (attaches itself to metadata) info=tableDescription) else: raise ValueError("No columns in table: {}".format(tableName))
"""Add a column to a table.
Parameters ---------- table : `sqlalchemy.Table`, `sqlalchemy.expression.TableClause` or `str` The table. columnDescription : `dict` Description of the column to be created. Should always contain: - name, descriptive name - type, valid column type May contain: - nullable, entry can be null - primary_key, mark this column as primary key - foreign_key, link to other table - doc, docstring """ table = self.metadata.tables[table]
"""Add a ForeignKeyConstraint to a table.
If the table or the ForeignKeyConstraint's target are views, or should not be included in this schema (because it is limited), does nothing.
Parameters ---------- table : `sqlalchemy.Table` or `str` The table. constraintDescription : `dict` Description of the ForeignKeyConstraint to be created. Should always contain: - src, list of source column names - tgt, list of target column names """ table = self.metadata.tables[table]
"""Make a Column entry for addition to a Table.
Parameters ---------- columnDescription : `dict` Description of the column to be created. Should always contain: - name, descriptive name - type, valid column type May contain: - nullable, entry can be null - primary_key, mark this column as primary key - doc, docstring
Returns ------- c : `sqlalchemy.Column` The created `Column` entry.
Raises ------ ValueError If the column description contains unsupported arguments """ # required # additional optional arguments can be passed through directly raise ValueError("Unhandled extra kwargs: {} for column: {}".format(description, columnName))
"""Convert configuration for a ForeignKeyConstraint to standard form and return the target table.
Parameters ---------- constraintDescription : `dict` Description of the ForeignKeyConstraint to be created. Should always contain: - src, list of source column names or single source column name - tgt, list of (table-qualified) target column names or single target column name
Returns ------- src : `tuple` Sequence of field names in the local table. tgt : `tuple` Sequence of table-qualified field names in the remote table. tgtTable : `str` Name of the target table. """ |