Assignment-3
1.Design a data model for a social media platform in Cassandra,
considering users, posts, and comments.
Ans =
1. Users Table
CREATE TABLE users (
user_id UUID PRIMARY KEY,
username TEXT,
email TEXT,
full_name TEXT,
profile_pic TEXT,
created_at TIMESTAMP
);
2.Posts Table
CREATE TABLE posts (
post_id UUID,
user_id UUID,
content TEXT,
image_url TEXT,
created_at TIMESTAMP,
PRIMARY KEY (user_id, created_at, post_id)
) WITH CLUSTERING ORDER BY (created_at DESC);
3. Comments Table
CREATE TABLE comments (
post_id UUID,
comment_id UUID,
user_id UUID,
comment_text TEXT,
created_at TIMESTAMP,
PRIMARY KEY (post_id, created_at, comment_id)
) WITH CLUSTERING ORDER BY (created_at DESC);
2.Write CQL queries for basic CRUD operations in Cassandra.
Ans =
1. Create Table
CREATE TABLE student (
student_id UUID PRIMARY KEY,
name TEXT,
age INT,
department TEXT,
email TEXT
);
2. Insert Data (CREATE)
INSERT INTO student (student_id, name, age, department, email)
VALUES (uuid(), 'Alice Johnson', 22, 'Computer Science', '
[email protected]');
3. Read Data (SELECT)
SELECT * FROM student;
4.Update Data(UPDATE)
UPDATE student
SET age = 23, email = '[email protected]'
WHERE name = 'Alice Johnson' ;
5.Delete Data(DELETE)
DELETE FROM student WHERE student_id = <UUID_VALUE>;
6.Drop Table(DELETE)
DROP TABLE student;
3.Install and configure Cassandra on a Linux system, documenting the process.
Ans =
Installing and Configuring Apache Cassandra on Ubuntu/Debian
(Using APT) Are:
1. Pre-Requirements
Before installing Cassandra, ensure your system meets the following requirements:
System Requirements
● 64-bit Ubuntu/Debian OS
● Java 8 or later (Required for Cassandra)
● At least 2 GB RAM (Recommended: 8 GB for production)
● 10 GB free disk space
Update System Packages
Before installation, update your system:
sudo apt update && sudo apt upgrade -y
2. Install Java (Required for Cassandra)
Cassandra requires Java 8 or later. Install OpenJDK 8:
sudo apt install openjdk-8-jdk -y
Verify Java Installation
java -version
Expected output (example):
openjdk version "1.8.0_xx"
3. Install Apache Cassandra
Add Cassandra Repository
echo "deb https://downloads.apache.org/cassandra/debian 40x main" | sudo tee -a
/etc/apt/sources.list.d/cassandra.list
Add GPG Key
wget -q -O - https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -
Update Package List and Install Cassandra
sudo apt update
sudo apt install cassandra -y
4. Start and Enable Cassandra Service
sudo systemctl start cassandra
sudo systemctl enable cassandra
Check Cassandra Service Status
sudo systemctl status cassandra
Expected output (Active running):
● cassandra.service - Apache Cassandra Server
Loaded: loaded (/lib/systemd/system/cassandra.service; enabled; vendor preset: enabled)
Active: active (running) since ...
5. Verify Cassandra Installation
Run the following command to check if Cassandra is running:
nodetool status
Expected output:
Datacenter: datacenter1
===============
Status=Up/Normal (UN)
To enter the Cassandra shell (CQLSH):
cqlsh
Expected output:
Connected to Test Cluster at 127.0.0.1:9042.
cqlsh>