Show Menu
Cheatography

Apache Cassandra CQL Cheat Sheet by

My most common CQLs for developing and administrating

Symbolic Link to an Encrypted LVM Volume

ls -lrtah /var/lib/cassandra
lrwxrwxrwx 1 cassandra cassandra 34 Sep 9 19:13 /var/lib/cassandra -> /media/SecureDataStore/cassandra
sudo chown -R cassandra:cassandra /var/lib/cassandra
sudo chown -R cassandra:cassandra /media/SecureDataStore/cassandra

Logging Into CQLSH

export CQLSH_HOST=<rpc address>
export CQLSH_PORT=9042
cqlsh -u cassandra
Password:
cassandra@cqlsh> exit

Creating DB Users, Roles, and Access

https://www.datastax.com/dev/blog/role-based-access-control-in-cassandra

CREATE ROLE supervisor;
GRANT MODIFY ON warehouse.orders TO supervisor;
GRANT SELECT ON warehouse.addresses TO supervisor;

CREATE ROLE bob WITH PASSWORD = 'password' AND LOGIN = true;
GRANT supervisor TO bob;

LIST ALL PERMISSIONS OF bob;

CREATE ROLE office_admin;
GRANT SELECT ON KEYSPACE office TO office_admin;
GRANT MODIFY ON KEYSPACE office TO office_admin;
GRANT office_admin TO bob;

REVOKE MODIFY ON KEYSPACE office TO office_admin;

Exploring Key Spaces and Tables

DESCRIBE keypsaces;
USE <yourkeyspace>;
DESCRIBE tables;
 

Minimum Dev Config­uration

sudo nano /etc/cassandra/cassandra.yaml
cluster_name: 'Name of Cluster'
rpc_address: <Your IP. Do not use a FQDN>
authenticator: PasswordAuthenticator

sudo chmod 777 /etc/security/limits.conf
echo "* - memlock unlimited" >> /etc/security/limits.conf
echo "* - nofile 100000" >> /etc/security/limits.conf
echo "* - nproc 32768" >> /etc/security/limits.conf
echo "* - as unlimited" >> /etc/security/limits.conf
sudo chmod 644 /etc/security/limits.conf

Start Stop Service

sudo -u cassandra cassandra
ps -ef | grep cassandra
sudo kill -9 <PID of cassandra>

Python Batch Inserts

from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import Cluster
from cassandra.query import BatchStatement
auth_provider_omni = PlainTextAuthProvider(
    username=settings.cassandra_username,
    password=settings.cassandra_password
)
cluster_omni = Cluster(
    [settings.cassandra_host],
    auth_provider=auth_provider_omni,
    port=settings.cassandra_port
    # ssl_options=ssl_opts
)
conn = self.cluster_omni.connect(
    settings.cassandra_keyspace_name
)

batch = BatchStatement()
sql_str = (
                'INSERT INTO ' + TABLE_PREFIX + '_' +
                location.lower() + '_' +
                demographic.lower() +
                ' (date,value) VALUES (?,?)'
)
sql = conn.prepare(sql_str)
for value in values:
    batch.add(sql, value['date'], value['value'])
conn.execute(batch)
batch.clear()
conn.shutdown()
           

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Selenium WebDriver Cheat Sheet Cheat Sheet
          ISTQB Test Automation Engineering Cheat Sheet
          Cypressio Cheat Sheet

          More Cheat Sheets by edendekker

          Jenkins CLI Cheat Sheet
          VIM Cheat Sheet Cheat Sheet