APACHE CASSANDRA

 

Introduction, Installation and 

Basic CQL Commands

AIM

To study Apache Cassandra, install Cassandra on the system, and execute basic CQL commands such as creating a keyspace, table, inserting and retrieving data.


SOFTWARE REQUIREMENTS

  • Operating System: Windows / Linux / Ubuntu

  • Apache Cassandra 4.x

  • Java JDK 8 or 11

  • Python (Optional for cqlsh)

  • Docker (Optional)


THEORY

1. Apache Cassandra

Apache Cassandra is an open-source, distributed, NoSQL database designed to handle large volumes of data across multiple servers with no single point of failure.

Key Features

  • Peer-to-peer architecture

  • High write performance

  • Column-family based storage

  • Horizontal scalability

  • Tunable consistency

  • Replication across data centers


2. Cassandra Architecture Components

ComponentDescription
Node        Basic unit of storage
Cluster        Collection of multiple nodes
Data Center        Logical grouping of nodes
Keyspace        Equivalent to database
Column Family (Table)        Structure to store rows
Partition Key        Determines data distribution
Replication Factor        Number of copies of data

3. Installation Procedure


A. Installation on Ubuntu / Linux

Step 1: Update System

sudo apt update

Step 2: Install Java

sudo apt install openjdk-11-jdk -y

Step 3: Add Cassandra Repository

echo "deb https://debian.cassandra.apache.org stable main" |
sudo tee /etc/apt/sources.list.d/cassandra.sources.list

Step 4: Add Repository Key

curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -

Step 5: Install Cassandra

sudo apt update sudo apt install cassandra -y

Step 6: Start Service

sudo systemctl start cassandra

Step 7: Open CQL Shell

cqlsh

B. Installation on Windows

(Not officially supported but works with binaries)

Steps

  1. Install Java 8 or 11

  2. Download Cassandra ZIP

  3. Extract to C:\cassandra

  4. Add C:\cassandra\bin to PATH

  5. Run:

    cassandra.bat
  6. Open shell:

    cqlsh

 Basic Cassandra CQL Commands


AIM

To execute Cassandra Query Language (CQL) commands for keyspace creation, table creation, insertion, updating, deletion, and selection.


COMMANDS & PROCEDURE


1. Create a Keyspace

CREATE KEYSPACE college WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': 1 };

2. Use the Keyspace

USE college;

3. Create a Table

CREATE TABLE student ( id INT PRIMARY KEY, name TEXT, age INT, marks INT );

4. Insert Records

INSERT INTO student (id, name, age, marks) VALUES (1, 'Alice', 20, 88); INSERT INTO student (id, name, age, marks) VALUES (2, 'Bob', 22, 91);

5. Select Records

SELECT * FROM student;

6. Update Records

UPDATE student SET marks = 95 WHERE id = 2;

7. Delete a Record

DELETE FROM student WHERE id = 1;

8. Drop Table

DROP TABLE student;

9. Drop Keyspace

DROP KEYSPACE college;

OBSERVATION

  • Keyspace was created successfully.

  • Table was created with columns id, name, age, marks.

  • Data was inserted and retrieved using CQL commands.

  • Cassandra shell executed commands without errors.


RESULT

The installation of Apache Cassandra was completed, and basic CQL commands for creating keyspace, table, inserting, updating, deleting, and retrieving records were successfully executed.

Comments

Popular posts from this blog

Database Management Systems DBMS Lab PCCSL408 Semester 4 KTU CS 2024 Scheme

DBMS Lab PCCSL408 2024 Scheme and Syllabus

Design a Database Schema for an Application Using ER Diagram from Problem Description