TimespanDatabaseRepresentation¶
- 
class lsst.daf.butler.TimespanDatabaseRepresentation¶
- Bases: - abc.ABC- An interface for representing a timespan in a database. - Notes - Much of this class’s interface is comprised of classmethods. Instances can be constructed via the - from_columnsor- fromLiteralmethods as a way to include timespan overlap operations in query JOIN or WHERE clauses.- TimespanDatabaseRepresentationimplementations are guaranteed to use the same interval definitions and edge-case behavior as the- Timespanclass. They are also guaranteed to round-trip- Timespaninstances exactly.- Attributes Summary - NAME- name- Return base logical name for the timespan column or expression ( - str).- Methods Summary - contains(other, …)- Return a SQLAlchemy expression representing containment. - extract(mapping, Any], name, None] = None)- Extract a timespan from a dictionary that represents a database row. - flatten(name, None] = None)- Return the actual column(s) that comprise this logical column. - fromLiteral(timespan, None])- Construct a database timespan from a literal - Timespaninstance.- from_columns(columns, name, None] = None)- Construct a database timespan from the columns of a table or subquery. - getFieldNames(name, None] = None)- Return the actual field names used by this representation. - hasExclusionConstraint()- Return - Trueif this representation supports exclusion constraints.- isEmpty()- Return a boolean SQLAlchemy expression for testing empty timespans. - isNull()- Return expression that tests whether the timespan is - NULL.- lower()- Return a SQLAlchemy expression representing a lower bound of a timespan. - makeFieldSpecs(nullable, name, None] = None, …)- Make objects that reflect the fields that must be added to table. - overlaps(other, …)- Return a SQLAlchemy expression representing timespan overlaps. - update(timespan, None], name, None] = None, …)- Add a timespan value to a dictionary that represents a database row. - upper()- Return a SQLAlchemy expression representing an upper bound of a timespan. - Attributes Documentation - 
NAME= 'timespan'¶
 - 
name¶
- Return base logical name for the timespan column or expression ( - str).- If the representation uses only one actual column, this should be the full name of the column. In other cases it is an unspecified common subset of the column names. 
 - Methods Documentation - 
contains(other: Union[_S, sqlalchemy.sql.elements.ColumnElement]) → sqlalchemy.sql.elements.ColumnElement¶
- Return a SQLAlchemy expression representing containment. - Returns a test for whether an in-database timespan contains another timespan or a time point. - Parameters: - other : type(self)orsqlalchemy.sql.ColumnElement
- The timespan or time to relate to - self; either an instance of the same- TimespanDatabaseRepresentationsubclass as- self, or a SQL column expression representing an- astropy.time.Time.
 - Returns: - contains : sqlalchemy.sql.ColumnElement
- A boolean SQLAlchemy expression object. 
 - Notes - See - Timespan.containsfor edge-case behavior.
- other : 
 - 
classmethod extract(mapping: Mapping[str, Any], name: Optional[str, None] = None) → lsst.daf.butler.core.timespan.Timespan | None[lsst.daf.butler.core.timespan.Timespan, None]¶
- Extract a timespan from a dictionary that represents a database row. - Parameters: - mapping : Mapping[str,Any]
- A dictionary representing a database row containing a - Timespanin this representation. Should have key(s) equal to the return value of- getFieldNames.
- name : str, optional
- Name for the logical column; a part of the name for multi-column representations. Defaults to - cls.NAME.
 - Returns: 
- mapping : 
 - 
flatten(name: Optional[str, None] = None) → Tuple[sqlalchemy.sql.elements.ColumnElement, ...]¶
- Return the actual column(s) that comprise this logical column. - Parameters: - name : str, optional
- If provided, a name for the logical column that should be used to label the columns. If not provided, the columns’ native names will be used. 
 - Returns: - columns : tuple[sqlalchemy.sql.ColumnElement]
- The true column or columns that back this object. 
 
- name : 
 - 
classmethod fromLiteral(timespan: Optional[lsst.daf.butler.core.timespan.Timespan, None]) → _S¶
- Construct a database timespan from a literal - Timespaninstance.- Parameters: - Returns: - tsRepr : TimespanDatabaseRepresentation
- A timespan expression object backed by - sqlalchemy.sql.literalcolumn expressions.
 
- tsRepr : 
 - 
classmethod from_columns(columns: sqlalchemy.sql.base.ColumnCollection, name: Optional[str, None] = None) → _S¶
- Construct a database timespan from the columns of a table or subquery. - Parameters: - columns : sqlalchemy.sql.ColumnCollections
- SQLAlchemy container for raw columns. 
- name : str, optional
- Name for the logical column; a part of the name for multi-column representations. Defaults to - cls.NAME.
 - Returns: - tsRepr : TimespanDatabaseRepresentation
- A timespan expression object backed by - sqlalchemy.sql.literalcolumn expressions.
 
- columns : 
 - 
classmethod getFieldNames(name: Optional[str, None] = None) → tuple¶
- Return the actual field names used by this representation. - Parameters: - name : str, optional
- Name for the logical column; a part of the name for multi-column representations. Defaults to - cls.NAME.
 - Returns: - names : tuple[str]
- Field name(s). Guaranteed to be the same as the names of the field specifications returned by - makeFieldSpecs.
 
- name : 
 - 
classmethod hasExclusionConstraint() → bool¶
- Return - Trueif this representation supports exclusion constraints.- Returns: 
 - 
isEmpty() → sqlalchemy.sql.elements.ColumnElement¶
- Return a boolean SQLAlchemy expression for testing empty timespans. - Returns: - empty : sqlalchemy.sql.ColumnElement
- A boolean SQLAlchemy expression object. 
 
- empty : 
 - 
isNull() → sqlalchemy.sql.elements.ColumnElement¶
- Return expression that tests whether the timespan is - NULL.- Returns a SQLAlchemy expression that tests whether this region is logically - NULL.- Returns: - isnull : sqlalchemy.sql.ColumnElement
- A boolean SQLAlchemy expression object. 
 
- isnull : 
 - 
lower() → sqlalchemy.sql.elements.ColumnElement¶
- Return a SQLAlchemy expression representing a lower bound of a timespan. - Returns: - lower : sqlalchemy.sql.ColumnElement
- A SQLAlchemy expression for a lower bound. 
 - Notes - If database holds - NULLfor a timespan then the returned expression should evaluate to 0. Main purpose of this and- uppermethod is to use them in generating SQL, in particular ORDER BY clause, to guarantee a predictable ordering. It may potentially be used for transforming boolean user expressions into SQL, but it will likely require extra attention to ordering issues.
- lower : 
 - 
classmethod makeFieldSpecs(nullable: bool, name: Optional[str, None] = None, **kwargs) → tuple¶
- Make objects that reflect the fields that must be added to table. - Makes one or more - ddl.FieldSpecobjects that reflect the fields that must be added to a table for this representation.- Parameters: - nullable : bool
- If - True, the timespan is permitted to be logically- NULL(mapped to- Nonein Python), though the corresponding value(s) in the database are implementation-defined. Nullable timespan fields default to NULL, while others default to (-∞, ∞).
- name : str, optional
- Name for the logical column; a part of the name for multi-column representations. Defaults to - cls.NAME.
- **kwargs
- Keyword arguments are forwarded to the - ddl.FieldSpecconstructor for all fields; implementations only provide the- name,- dtype, and- defaultarguments themselves.
 - Returns: - specs : tuple[ddl.FieldSpec]
- Field specification objects; length of the tuple is subclass-dependent, but is guaranteed to match the length of the return values of - getFieldNamesand- update.
 
- nullable : 
 - 
overlaps(other: Union[_S, sqlalchemy.sql.elements.ColumnElement]) → sqlalchemy.sql.elements.ColumnElement¶
- Return a SQLAlchemy expression representing timespan overlaps. - Parameters: - other : type(self)
- The timespan or time to overlap - selfwith. If a single time, this is a synonym for- contains.
 - Returns: - overlap : sqlalchemy.sql.ColumnElement
- A boolean SQLAlchemy expression object. 
 - Notes - See - Timespan.overlapsfor edge-case behavior.
- other : 
 - 
classmethod update(timespan: Optional[lsst.daf.butler.core.timespan.Timespan, None], name: Optional[str, None] = None, result: Optional[Dict[str, Any], None] = None) → Dict[str, Any]¶
- Add a timespan value to a dictionary that represents a database row. - Parameters: - timespan
- A timespan literal, or - Nonefor- NULL.
- name : str, optional
- Name for the logical column; a part of the name for multi-column representations. Defaults to - cls.NAME.
- result : dict[str,Any], optional
- A dictionary representing a database row that fields should be added to, or - Noneto create and return a new one.
 - Returns: 
 - 
upper() → sqlalchemy.sql.elements.ColumnElement¶
- Return a SQLAlchemy expression representing an upper bound of a timespan. - Returns: - upper : sqlalchemy.sql.ColumnElement
- A SQLAlchemy expression for an upper bound. 
 - Notes - If database holds - NULLfor a timespan then the returned expression should evaluate to 0. Also see notes for- lowermethod.
- upper : 
 
-