lsst.dax.apdb g9290983e33+d2d81de7f7
 
Loading...
Searching...
No Matches
lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema Class Reference

Public Member Functions

 __init__ (self, cassandra.cluster.Session session, str keyspace, Mapping[ApdbTables, Table] table_schemas, str prefix="", bool time_partition_tables=False, bool enable_replica=False, bool replica_skips_diaobjects=False, bool has_chunk_sub_partitions=True, bool has_visit_detector_table=True)
 
bool replication_enabled (self)
 
bool empty (self)
 
dict[ApdbTables, list[str]] existing_tables (self, *ApdbTables args)
 
bool check_column (self, ApdbTables|ExtraTables table_enum, str column)
 
str tableName (self, ApdbTables|ExtraTables table_name, int|None time_partition=None)
 
str keyspace (self)
 
Mapping[str, schema_model.ColumngetColumnMap (self, ApdbTables|ExtraTables table_name)
 
list[str] apdbColumnNames (self, ApdbTables|ExtraTables table_name)
 
list[str] partitionColumns (self, ApdbTables|ExtraTables table_name)
 
list[str] clusteringColumns (self, ApdbTables|ExtraTables table_name)
 
None makeSchema (self, *, bool drop=False, ApdbCassandraTimePartitionRange|None part_range=None, int|None replication_factor=None, CreateTableOptions|None table_options=None)
 
int table_row_size (self, ApdbTables|ExtraTables table)
 
list[ApdbTablestime_partitioned_tables (self)
 

Protected Member Functions

Mapping[ApdbTables, schema_model.Table_apdb_tables_schema (self, bool time_partition_tables)
 
Mapping[ExtraTables, schema_model.Table_extra_tables_schema (self)
 
CreateTableOptions|None _update_table_options (self, CreateTableOptions|None options)
 
None _makeTableSchema (self, ApdbTables|ExtraTables table, bool drop=False, ApdbCassandraTimePartitionRange|None part_range=None, CreateTableOptions|None table_options=None)
 
list[str] _tableColumns (self, ApdbTables|ExtraTables table_name)
 
schema_model.Table _table_schema (self, ApdbTables|ExtraTables table)
 

Protected Attributes

 _session = session
 
str _keyspace = keyspace
 
 _table_schemas = table_schemas
 
 _prefix = prefix
 
 _time_partition_tables = time_partition_tables
 
 _enable_replica = enable_replica
 
 _replica_skips_diaobjects = replica_skips_diaobjects
 
 _has_chunk_sub_partitions = has_chunk_sub_partitions
 
 _has_visit_detector_table = has_visit_detector_table
 
Mapping[ApdbTables, schema_model.Table_apdb_tables = self._apdb_tables_schema(time_partition_tables)
 
Mapping[ExtraTables, schema_model.Table_extra_tables = self._extra_tables_schema()
 

Static Protected Attributes

dict _type_map
 
list _time_partitioned_tables
 
list _spatially_partitioned_tables = [ApdbTables.DiaObjectLast]
 

Detailed Description

Class for management of APDB schema.

Parameters
----------
session : `cassandra.cluster.Session`
    Cassandra session object
keyspace : `str`
    Keyspace name for all tables.
schema_file : `str`
    Name of the YAML schema file.
schema_name : `str`, optional
    Name of the schema in YAML files.
prefix : `str`, optional
    Prefix to add to all schema elements.
time_partition_tables : `bool`
    If `True` then schema will have a separate table for each time
    partition.
enable_replica : `bool`, optional
    If `True` then use additional tables for replica chunks.
has_chunk_sub_partitions : `bool`, optional
    If `True` then replica chunk tables have sub-partition columns. Only
    used if ``enable_replica`` is `True`.

Member Function Documentation

◆ _apdb_tables_schema()

Mapping[ApdbTables, schema_model.Table] lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema._apdb_tables_schema ( self,
bool time_partition_tables )
protected
Generate schema for regular APDB tables.

◆ _extra_tables_schema()

Mapping[ExtraTables, schema_model.Table] lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema._extra_tables_schema ( self)
protected
Generate schema for extra tables.

◆ _table_schema()

schema_model.Table lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema._table_schema ( self,
ApdbTables | ExtraTables table )
protected
Return schema definition for a table.

◆ _tableColumns()

list[str] lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema._tableColumns ( self,
ApdbTables | ExtraTables table_name )
protected
Return set of columns in a table

Parameters
----------
table_name : `ApdbTables`
    Name of the table.

Returns
-------
column_defs : `list`
    List of strings in the format "column_name type".

◆ _update_table_options()

CreateTableOptions | None lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema._update_table_options ( self,
CreateTableOptions | None options )
protected
Extend table options with options for internal tables.

◆ apdbColumnNames()

list[str] lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.apdbColumnNames ( self,
ApdbTables | ExtraTables table_name )
Return a list of columns names for a table as defined in APDB
schema.

Parameters
----------
table_name : `ApdbTables` or `ExtraTables`
    Enum for a table in APDB schema.

Returns
-------
columns : `list` of `str`
    Names of regular columns in the table.

◆ check_column()

bool lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.check_column ( self,
ApdbTables | ExtraTables table_enum,
str column )
Check for the existence of the column in a given table.

Parameters
----------
table_enum : `ApdbTables` or `ExtraTables`
    Table to check for a column.
column : `str`
    Name of the column to check.

Returns
-------
exists : `bool`
    True if column exists, False otherwise.

Raises
------
LookupError
    Raised if table does not exist.

◆ clusteringColumns()

list[str] lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.clusteringColumns ( self,
ApdbTables | ExtraTables table_name )
Return a list of columns used for clustering.

Parameters
----------
table_name : `ApdbTables`
    Table name in APDB schema

Returns
-------
columns : `list` of `str`
    Names of columns for used for clustering.

◆ empty()

bool lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.empty ( self)
Return True if database schema is empty.

Returns
-------
empty : `bool`
    `True` if none of the required APDB tables exist in the database,
    `False` if all required tables exist.

Raises
------
InconsistentSchemaError
    Raised when some of the required tables exist but not all.

◆ existing_tables()

dict[ApdbTables, list[str]] lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.existing_tables ( self,
*ApdbTables args )
Return the list of existing table names for given table.

Parameters
----------
*args : `ApdbTables`
    Tables for which to return their existing table names.

Returns
-------
tables : `dict` [`ApdbTables`, `list`[`str`]]
    Mapping of the APDB table to the list of the existing table names.
    More than one name can be present in the list if configuration
    specifies per-partition tables.

◆ getColumnMap()

Mapping[str, schema_model.Column] lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.getColumnMap ( self,
ApdbTables | ExtraTables table_name )
Return mapping of column names to Column definitions.

Parameters
----------
table_name : `ApdbTables`
    One of known APDB table names.

Returns
-------
column_map : `dict`
    Mapping of column names to `ColumnDef` instances.

◆ keyspace()

str lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.keyspace ( self)
Return Cassandra keyspace for APDB tables.

◆ makeSchema()

None lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.makeSchema ( self,
* ,
bool drop = False,
ApdbCassandraTimePartitionRange | None part_range = None,
int | None replication_factor = None,
CreateTableOptions | None table_options = None )
Create or re-create all tables.

Parameters
----------
drop : `bool`
    If True then drop tables before creating new ones. Note that
    only tables are dropped and not the whole keyspace.
part_range : `ApdbCassandraTimePartitionRange` or `None`
    Start and end partition number for time partitions. Used to create
    per-partition DiaObject, DiaSource, and DiaForcedSource tables. If
    `None` then per-partition tables are not created.
replication_factor : `int`, optional
    Replication factor used when creating new keyspace, if keyspace
    already exists its replication factor is not changed.

◆ partitionColumns()

list[str] lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.partitionColumns ( self,
ApdbTables | ExtraTables table_name )
Return a list of columns used for table partitioning.

Parameters
----------
table_name : `ApdbTables`
    Table name in APDB schema

Returns
-------
columns : `list` of `str`
    Names of columns used for partitioning.

◆ replication_enabled()

bool lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.replication_enabled ( self)
True when replication is enabled (`bool`).

◆ table_row_size()

int lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.table_row_size ( self,
ApdbTables | ExtraTables table )
Return an estimate of the row size of a given table.

Parameters
----------
table : `ApdbTables` or `ExtraTables`

Returns
-------
size : `int`
    An estimate of a table row size.

Notes
-----
Returned size is not exact. When table has variable-size columns (e.g.
strings) may be incorrect. Stored data size or wire-level protocol size
can be smaller if some columns are not set or set to NULL.

◆ tableName()

str lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.tableName ( self,
ApdbTables | ExtraTables table_name,
int | None time_partition = None )
Return Cassandra table name for APDB table.

Parameters
----------
table_name : `ApdbTables` or `ExtraTables`
    Table enum for which to generate table name.
time_partition : `int`, optional
    Optional time partition, only used for tables that support time
    patitioning.

◆ time_partitioned_tables()

list[ApdbTables] lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.time_partitioned_tables ( self)
Make the list of time-partitioned tables.

Returns
-------
tables : `list` [`ApdbTables`]
    Tables the are time-partitioned.

Member Data Documentation

◆ _time_partitioned_tables

lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema._time_partitioned_tables
staticprotected
Initial value:
= [
ApdbTables.DiaObject,
ApdbTables.DiaSource,
ApdbTables.DiaForcedSource,
]

◆ _type_map

dict lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema._type_map
staticprotected
Initial value:
= {
felis.datamodel.DataType.double: "DOUBLE",
felis.datamodel.DataType.float: "FLOAT",
felis.datamodel.DataType.timestamp: "TIMESTAMP",
felis.datamodel.DataType.long: "BIGINT",
felis.datamodel.DataType.int: "INT",
felis.datamodel.DataType.short: "SMALLINT",
felis.datamodel.DataType.byte: "TINYINT",
felis.datamodel.DataType.binary: "BLOB",
felis.datamodel.DataType.char: "TEXT",
felis.datamodel.DataType.string: "TEXT",
felis.datamodel.DataType.unicode: "TEXT",
felis.datamodel.DataType.text: "TEXT",
felis.datamodel.DataType.boolean: "BOOLEAN",
schema_model.ExtraDataTypes.UUID: "UUID",
}

The documentation for this class was generated from the following file: