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.Column] | getColumnMap (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[ApdbTables] | time_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] |
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`.
|
protected |
Generate schema for regular APDB tables.
|
protected |
Generate schema for extra tables.
|
protected |
Return schema definition for a table.
|
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".
|
protected |
Extend table options with options for internal tables.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| str lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.keyspace | ( | self | ) |
Return Cassandra keyspace for APDB tables.
| 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.
| 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.
| bool lsst.dax.apdb.cassandra.apdbCassandraSchema.ApdbCassandraSchema.replication_enabled | ( | self | ) |
True when replication is enabled (`bool`).
| 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.
| 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.
| 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.
|
staticprotected |
|
staticprotected |