Cassandra - ( CosmosDB APIs )
Syntax
CREATE KEYSPACE <keyspace_name> WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': <num_replicas>} ;
CREATE TABLE <table_name> (
<column_name> <data_type> PRIMARY KEY,
<column_name> <data_type>,
<column_name> <data_type>,
...
) WITH <option_name> = <option_value> AND <option_name> = <option_value> ;
INSERT INTO <table_name>
(<column_name>, <column_name>, ...)
VALUES
(<value>, <value>, ...);
Example
CREATE KEYSPACE my_keyspace WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 3};
CREATE TABLE my_table (
id INT PRIMARY KEY,
name TEXT,
age INT
);
INSERT INTO my_table (id, name, age) VALUES (1, 'John', 30);
Output
(keyspace and table created)
(id, name, age row inserted in the table)
Explanation
Cassandra is a NoSQL database that is highly scalable and distributed. It has a masterless architecture and uses a peer-to-peer distribution model. Each node in Cassandra acts as both a coordinator and a data store. Cassandra uses column-family data model and is based on the CQL (Cassandra Query Language).
The syntax for creating a keyspace in Cassandra is CREATE KEYSPACE <keyspace_name> WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': <num_replicas>}
. The replication_factor
parameter determines the number of replicas for each data key.
The syntax for creating a table in Cassandra is CREATE TABLE <table_name> (<column_name> <data_type> PRIMARY KEY, <column_name> <data_type>, ...) WITH <option_name> = <option_value> AND <option_name> = <option_value> ;
. The primary key column(s) determines the partition key(s) and the clustering column(s).
The syntax for inserting data into a table in Cassandra is INSERT INTO <table_name> (<column_name>, <column_name>, ...) VALUES (<value>, <value>, ...);
.
Use
Cassandra is used for big data and high-velocity use cases where data needs to be written and read in real-time, without delay. It can handle large amounts of data with high write and read throughput.
Important Points
- Cassandra is a highly scalable and distributed NoSQL database
- It uses a masterless architecture and peer-to-peer distribution model
- Cassandra uses CQL (Cassandra Query Language)
- It is designed for big data and high-velocity use cases.
Summary
Cassandra is a highly scalable and distributed NoSQL database that uses a masterless architecture and peer-to-peer distribution model. It uses CQL and is designed for big data and high-velocity use cases. It can handle large amounts of data with high write and read throughput.