dse.metadata - Schema and Ring Topology
Module Data
cql_keywords
Set of keywords in CQL.
Derived from …/cassandra/src/java/org/apache/cassandra/cql3/Cql.g
cql_keywords_unreserved
Set of unreserved keywords in CQL.
Derived from …/cassandra/src/java/org/apache/cassandra/cql3/Cql.g
cql_keywords_reserved
Set of reserved keywords in CQL.
class Metadata
Holds a representation of the cluster schema and topology.
Attributes
cluster_name
= NoneThe string name of the cluster.
partitioner
= NoneThe string name of the partitioner for the cluster.
token_map
= NoneA TokenMap instance describing the ring topology.
keyspaces
= NoneA map from keyspace names to matching KeyspaceMetadata instances.
Methods
export_schema_as_string
()Returns a string that can be executed as a query in order to recreate the entire schema. The string is formatted to be human readable.
get_replicas
(keyspace, key)Returns a list of Host instances that are replicas for a given
partition key.
add_or_return_host
(host)Returns a tuple (host, new), where host is a Host
instance, and new is a bool indicating whether
the host was newly added.
all_hosts
()Returns a list of all known Host instances in the cluster.
Schemas
class KeyspaceMetadata
A representation of the schema for a single keyspace.
Attributes
name
= NoneThe string name of the keyspace.
durable_writes
= TrueA boolean indicating whether durable writes are enabled for this keyspace or not.
replication_strategy
= NoneA ReplicationStrategy subclass object.
tables
= NoneA map from table names to instances of TableMetadata.
indexes
= NoneA dict mapping index names to IndexMetadata instances.
user_types
= NoneA map from user-defined type names to instances of UserType.
functions
= NoneA map from user-defined function signatures to instances of Function.
aggregates
= NoneA map from user-defined aggregate signatures to instances of Aggregate.
views
= NoneA dict mapping view names to MaterializedViewMetadata instances.
Methods
export_as_string
()Returns a CQL query string that can be used to recreate the entire keyspace, including user-defined types and tables.
as_cql_query
()Returns a CQL query string that can be used to recreate just this keyspace, not including user-defined types and tables.
class UserType
A user defined type, as created by CREATE TYPE statements.
User-defined types were introduced in Cassandra 2.1.
New in version 2.1.0.Attributes
keyspace
= NoneThe string name of the keyspace in which this type is defined.
name
= NoneThe name of this type.
field_names
= NoneAn ordered list of the names for each field in this user-defined type.
field_types
= NoneAn ordered list of the types for each field in this user-defined type.
Methods
as_cql_query
(formatted=False)Returns a CQL query that can be used to recreate this type.
If formatted is set to True, extra whitespace will
be added to make the query more readable.
class Function
A user defined function, as created by CREATE FUNCTION statements.
User-defined functions were introduced in Cassandra 2.2
New in version 2.6.0.Attributes
keyspace
= NoneThe string name of the keyspace in which this function is defined
name
= NoneThe name of this function
argument_types
= NoneAn ordered list of the types for each argument to the function
argument_names
= NoneAn ordered list of the names of each argument to the function
return_type
= NoneReturn type of the function
language
= NoneLanguage of the function body
body
= NoneFunction body string
called_on_null_input
= NoneFlag indicating whether this function should be called for rows with null values (convenience function to avoid handling nulls explicitly if the result will just be null)
Methods
as_cql_query
(formatted=False)Returns a CQL query that can be used to recreate this function.
If formatted is set to True, extra whitespace will
be added to make the query more readable.
class Aggregate
A user defined aggregate function, as created by CREATE AGGREGATE statements.
Aggregate functions were introduced in Cassandra 2.2
New in version 2.6.0.Attributes
keyspace
= NoneThe string name of the keyspace in which this aggregate is defined
name
= NoneThe name of this aggregate
argument_types
= NoneAn ordered list of the types for each argument to the aggregate
state_func
= NoneName of a state function
state_type
= NoneType of the aggregate state
final_func
= NoneName of a final function
initial_condition
= NoneInitial condition of the aggregate
return_type
= NoneReturn type of the aggregate
Methods
as_cql_query
(formatted=False)Returns a CQL query that can be used to recreate this aggregate.
If formatted is set to True, extra whitespace will
be added to make the query more readable.
class TableMetadata
A representation of the schema for a single table.
Attributes
primary_key
A list of ColumnMetadata representing the components of
the primary key for this table.
is_cql_compatible
A boolean indicating if this table can be represented as CQL in export
extensions
= NoneMetadata describing configuration for table extensions
keyspace_name
= NoneString name of this Table’s keyspace
name
= NoneThe string name of the table.
partition_key
= NoneA list of ColumnMetadata instances representing the columns in
the partition key for this table. This will always hold at least one
column.
clustering_key
= NoneA list of ColumnMetadata instances representing the columns
in the clustering key for this table. These are all of the
primary_key columns that are not in the partition_key.
Note that a table may have no clustering keys, in which case this will be an empty list.
columns
= NoneA dict mapping column names to ColumnMetadata instances.
indexes
= NoneA dict mapping index names to IndexMetadata instances.
options
= NoneA dict mapping table option names to their specific settings for this table.
triggers
= NoneA dict mapping trigger names to TriggerMetadata instances.
views
= NoneA dict mapping view names to MaterializedViewMetadata instances.
Methods
export_as_string
()Returns a string of CQL queries that can be used to recreate this table along with all indexes on it. The returned string is formatted to be human readable.
as_cql_query
(formatted=False)Returns a CQL query that can be used to recreate this table (index
creations are not included). If formatted is set to True,
extra whitespace will be added to make the query human readable.
class ColumnMetadata
A representation of a single column in a table.
Attributes
table
= NoneThe TableMetadata this column belongs to.
name
= NoneThe string name of this column.
cql_type
= NoneThe CQL type for the column.
is_static
= FalseIf this column is static (available in Cassandra 2.1+), this will
be True, otherwise False.
is_reversed
= FalseIf this column is reversed (DESC) as in clustering order
class IndexMetadata
A representation of a secondary index on a column.
Attributes
keyspace_name
= NoneA string name of the keyspace.
table_name
= NoneA string name of the table this index is on.
name
= NoneA string name for the index.
kind
= NoneA string representing the kind of index (COMPOSITE, CUSTOM,…).
index_options
= {}A dict of index options.
Methods
as_cql_query
()Returns a CQL query that can be used to recreate this index.
export_as_string
()Returns a CQL query string that can be used to recreate this index.
class MaterializedViewMetadata
A representation of a materialized view on a table
Attributes
extensions
= NoneMetadata describing configuration for table extensions
keyspace_name
= NoneA string name of the view.
name
= NoneA string name of the view.
base_table_name
= NoneA string name of the base table for this view.
partition_key
= NoneA list of ColumnMetadata instances representing the columns in
the partition key for this view. This will always hold at least one
column.
clustering_key
= NoneA list of ColumnMetadata instances representing the columns
in the clustering key for this view.
Note that a table may have no clustering keys, in which case this will be an empty list.
columns
= NoneA dict mapping column names to ColumnMetadata instances.
include_all_columns
= NoneA flag indicating whether the view was created AS SELECT *
where_clause
= NoneString WHERE clause for the view select statement. From server metadata
options
= NoneA dict mapping table option names to their specific settings for this view.
Methods
as_cql_query
(formatted=False)Returns a CQL query that can be used to recreate this function.
If formatted is set to True, extra whitespace will
be added to make the query more readable.
Tokens and Ring Topology
class TokenMap
Information about the layout of the ring.
Attributes
token_class
= NoneA subclass of Token, depending on what partitioner the cluster uses.
ring
= NoneAn ordered list of Token instances in the ring.
tokens_to_hosts_by_ks
= NoneMethods
get_replicas
(keyspace, token)class Token
Abstract class representing a token.
class Murmur3Token
A token for Murmur3Partitioner.
token is an int or string representing the token.
class MD5Token
A token for RandomPartitioner.
class BytesToken
A token for ByteOrderedPartitioner.
Class Methods
from_string
(token_string)token_string should be the string representation from the server.
Attributes
ReplicationStrategy
alias of dse.metadata._ReplicationStrategy
class SimpleStrategy
Attributes
replication_factor
= NoneThe replication factor for this keyspace.
Methods
export_for_schema
()Returns a string version of these replication options which are suitable for use in a CREATE KEYSPACE statement.
class NetworkTopologyStrategy
Attributes
dc_replication_factors
= NoneA map of datacenter names to the replication factor for that DC.
Methods
export_for_schema
()Returns a string version of these replication options which are suitable for use in a CREATE KEYSPACE statement.
class LocalStrategy
Methods
export_for_schema
()Returns a string version of these replication options which are suitable for use in a CREATE KEYSPACE statement.