Menu

cassandra.metadata - Schema and Ring Topology

cassandra.metadata.cql_keywords

set() -> new empty set object set(iterable) -> new set object

Build an unordered collection of unique elements.

cassandra.metadata.cql_keywords_unreserved

set() -> new empty set object set(iterable) -> new set object

Build an unordered collection of unique elements.

cassandra.metadata.cql_keywords_reserved

set() -> new empty set object set(iterable) -> new set object

Build an unordered collection of unique elements.

class cassandra.metadata.Metadata

Holds a representation of the cluster schema and topology.

add_or_return_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.

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_host

Find a host in the metadata for a specific endpoint. If a string inet address and port are passed, iterate all hosts to match the broadcast_rpc_address and broadcast_rpc_port attributes.

get_replicas

Returns a list of Host instances that are replicas for a given partition key.

Schemas

class cassandra.metadata.KeyspaceMetadata

A representation of the schema for a single keyspace.

as_cql_query

Returns a CQL query string that can be used to recreate just this keyspace, not including user-defined types and tables.

export_as_string

Returns a CQL query string that can be used to recreate the entire keyspace, including user-defined types and tables.

class cassandra.metadata.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.

as_cql_query

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 cassandra.metadata.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.

as_cql_query

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 cassandra.metadata.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.

as_cql_query

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 cassandra.metadata.TableMetadata

A representation of the schema for a single table.

as_cql_query

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.

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.

property is_cql_compatible

A boolean indicating if this table can be represented as CQL in export

property primary_key

A list of ColumnMetadata representing the components of the primary key for this table.

class cassandra.metadata.TableMetadataV3

For C* 3.0+. option_maps take a superset of map names, so if nothing changes structurally, new option maps can just be appended to the list.

property is_cql_compatible

A boolean indicating if this table can be represented as CQL in export

class cassandra.metadata.TableMetadataDSE68
class cassandra.metadata.ColumnMetadata

A representation of a single column in a table.

class cassandra.metadata.IndexMetadata

A representation of a secondary index on a column.

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 cassandra.metadata.MaterializedViewMetadata

A representation of a materialized view on a table

as_cql_query

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 cassandra.metadata.VertexMetadata

A representation of a vertex on a table

class cassandra.metadata.EdgeMetadata

A representation of an edge on a table

Tokens and Ring Topology

class cassandra.metadata.TokenMap

Information about the layout of the ring.

get_replicas

Get a set of Host instances representing all of the replica nodes for a given Token.

class cassandra.metadata.Token

Abstract class representing a token.

class cassandra.metadata.Murmur3Token

A token for Murmur3Partitioner.

token is an int or string representing the token.

class cassandra.metadata.MD5Token

A token for RandomPartitioner.

class cassandra.metadata.BytesToken

A token for ByteOrderedPartitioner.

classmethod from_string(token_string)

token_string should be the string representation from the server.

cassandra.metadata.ReplicationStrategy

alias of cassandra.metadata._ReplicationStrategy

class cassandra.metadata.ReplicationFactor

Represent the replication factor of a keyspace.

class cassandra.metadata.SimpleStrategy
export_for_schema

Returns a string version of these replication options which are suitable for use in a CREATE KEYSPACE statement.

property replication_factor

The replication factor for this keyspace.

For backward compatibility, this returns the cassandra.metadata.ReplicationFactor.full_replicas value of cassandra.metadata.SimpleStrategy.replication_factor_info.

class cassandra.metadata.NetworkTopologyStrategy
export_for_schema

Returns a string version of these replication options which are suitable for use in a CREATE KEYSPACE statement.

class cassandra.metadata.LocalStrategy
export_for_schema

Returns a string version of these replication options which are suitable for use in a CREATE KEYSPACE statement.

cassandra.metadata.group_keys_by_replica()

Returns a dict with the keys grouped per host. This can be used to more accurately group by IN clause or to batch the keys per host.

If a valid replica is not found for a particular key it will be grouped under NO_VALID_REPLICA

Example usage:

>>> result = group_keys_by_replica(
...     session, "system", "peers",
...     (("127.0.0.1", ), ("127.0.0.2", )))