Db - Cassandra

> Database

1 - About

Advertising

3 - Data Structure

Cassandra has support for modelling time series data wherein each row can have dynamic number of columns.

4 - Installation

docker run ^
  --name cassandra ^
  -d ^
  cassandra:3.11.5 
  • then
docker exec -it cassandra bash
cqlsh localhost
  • Query
SELECT cluster_name, listen_address FROM system.local;
 cluster_name | listen_address
--------------+----------------
 Test Cluster |     172.17.0.3
  • Create a keyspace (A keyspace is the cassandra name for a SQL schema) - default, schema are built-in words that cannot be used otherwise you get: SyntaxException: line 1:16 no viable alternative at input 'schema' (create keyspace [schema]…)
CREATE keyspace mySchema WITH replication = {'class':'SimpleStrategy','replication_factor':1};
USE mySchema;
CREATE TABLE t (
    pk INT,
    t INT,
    v text,
    s text static,
    PRIMARY KEY (pk, t)
);
 
INSERT INTO t (pk, t, v, s) VALUES (0, 0, 'val0', 'static0');
INSERT INTO t (pk, t, v, s) VALUES (0, 1, 'val1', 'static1');
 
SELECT * FROM t;
 pk | t | s       | v
----+---+---------+------
  0 | 0 | static1 | val0
  0 | 1 | static1 | val1
Advertising