cql - Cassandra Query Language Interface

Cassandra Query Language interface.

cassy.cql.create_keyspace(keyspace, session, replication='simple')[source]

Create keyspace via session if neccessary.

cassy.cql.get_cluster_name(session)[source]

Querry session for current cluster name.

Parameters

session (cassandra.cluster.Session) – cassandra.session.Session Used to query the cluster for its name.

Returns

Name of the cassandra cluster, the current session is connected to.

Return type

str

cassy.cql.list_column_values(cluster, session, keyspace, table, column)[source]

List all column values of table in keyspace.

Parameters
  • cluster (cassandra.cluster.Cluster) – cassandra.cluster.Cluster object holding the cassandra database.

  • session (cassandra.cluster.Session, default=None) –

    cassandra.session.Session used to query the table for clumn values.

  • keyspace (str) – String specifying the keyspace of the cluster where table is to be found.

  • table (str) – String specifying the table inside the keyspace of cluster of which the column labels are to be listed.

  • column (Number, str) – Column specifier of which the values are to be listed.

Returns

List of strings specifying the found column values

Return type

list

Raises

KeyError – Key Error raised if keyspace, table or column are unsuccesfully white-listed.

cassy.cql.get_all_entries(cluster, session, keyspace, table)[source]

Get all rows of a table.

Parameters
Returns

List of dictionairies of found entries.

Return type

list

Raises

KeyError – Key Error raised if keyspace or table are unsuccesfully white-listed.

cassy.cql.drop_row(cns, keyspace, table, primary_key, value)[source]

Drop(delete) a cassandra table row.

Parameters
Raises

KeyError – Key Error raised if keyspace, table, primary_key, value are unsuccesfully white-listed.

Examples

Dropping a row from the Martin Crawford database assuming a cluster and session were created using cassy.casdriv.connect_session():

drop_row(
    cns=(cluster, session),
    keyspace="crawford",
    table="common_fruiting_trees",
    primary_key="latin",
    value="Prunus domestica",
)
cassy.cql.drop_all_rows(cluster, session, keyspace, table)[source]

Drop(delete) an entire tables rows/content.

Parameters
  • cluster (cassandra.cluster.Cluster) –

    cassandra.cluster.Cluster object holding the cassandra database.

  • session (cassandra.cluster.Session) –

    cassandra.session.Session Use to execute query statement.

  • keyspace (str) – String specifying the default keyspace the table is found.

  • table (str) – String specifying the table of which to drop all rows.

Raises

KeyError – Key Error raised if keyspace or table are unsuccesfully white-listed.