APACHE CASSANDRA ADVANCED CRUD OPERATIONS
Advanced CRUD (Create, Read, Update, Delete) With Filtering, Batch, TTL, and Lightweight Transactions
AIM
To perform advanced CRUD operations in Apache Cassandra including
-
Batch operations
-
Conditional updates (LWT)
-
TTL (Time-To-Live)
-
Filtering
-
Secondary indexes
-
Updating collections (list, set, map)
SOFTWARE REQUIREMENTS
-
Apache Cassandra 4.x
-
Java JDK 8/11
-
cqlsh client
-
Ubuntu/Windows environment
THEORY
Cassandra provides more advanced data manipulation features compared to basic CRUD:
1. TTL (Time to Live)
A feature that automatically expires data after a specified number of seconds.
2. Batch Statements
Used to perform multiple writes atomically.
3. Lightweight Transactions (LWT)
Performed using IF EXISTS or IF condition, used for conditional updates.
4. Filtering
Allows non-primary-key filtering using ALLOW FILTERING.
5. Collection Types
-
List → ordered
-
Set → unique values
-
Map → key–value pairs
6. Secondary Index
Allows filtering on non-primary-key columns.
⭐ PROCEDURE & COMMANDS
1. Create Keyspace and Table
2. INSERT with Collections
3. UPDATE Collection Values
Append to List
Remove from List
Add to Set
Update Map Value
⭐ 4. DELETE Operations
Delete a single column
Delete collection elements
Delete entire row
⭐ 5. TTL (Time-to-Live)
Insert with TTL
(Record expires after 30 seconds)
Update with TTL
⭐ 6. Batch Operations
⭐ 7. Conditional Updates (Lightweight Transactions)
⭐ 8. Secondary Index & Filtering
Create Index
Filter Query
⭐ RESULT
-
Collection types were successfully inserted and modified.
-
TTL automatically deleted records.
-
Batch operations allowed atomic multi-statements.
-
LWT prevented race conditions by verifying conditions.
-
Index improved filtering on non-key columns.
Comments
Post a Comment