Cassandra - Lab 1
In this lab session, we will explore Apache Cassandra by setting up a Docker Cassandra instance using the provided command. We will cover the following:
- Launching a Docker Cassandra Container
- Connecting to the Cassandra Cluster
- Creating a Keyspace and a Table
- Inserting and Querying Data
1. Starting Cassandra
Steps
- Start up Docker
- Open your Terminal
-
Execute the following command
Info
This command creates a Docker container named "cassandra-instance" running the Cassandra image, maps port 9042 on your host to port 9042 inside the container, and runs Cassandra in the background.
Expected results
- The terminal will show the container ID
2. Connecting to the Cassandra Cluster
Steps
- Open the Terminal (or stay in the same Terminal window)
- Execute the following command
Expected results
-
The following information in the Terminal
3. Create a namespace and a table
Steps
-
Create a namespace and a table where the namespace is called
people
and the table is nammedperson
by copying and pasting the following content in the CQL shell -
Run the folloiwing command in the CQL shell
Expected results
-
Namespace and table created, showing the following in the Terminal
CREATE KEYSPACE people WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true; CREATE TABLE people.person ( id uuid PRIMARY KEY, age int, name text ) WITH additional_write_policy = '99p' AND bloom_filter_fp_chance = 0.01 AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} AND cdc = false AND comment = '' AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'} AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'} AND memtable = 'default' AND crc_check_chance = 1.0 AND default_time_to_live = 0 AND extensions = {} AND gc_grace_seconds = 864000 AND max_index_interval = 2048 AND memtable_flush_period_in_ms = 0 AND min_index_interval = 128 AND read_repair = 'BLOCKING' AND speculative_retry = '99p';
4. Inserting data
Steps
-
Run the following command in the CQL shell
-
Retrieve data from the
person
table running the following command in the CQL shell
Expected results
-
The
person
data with this similar output