Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Key Features of Cassandra:

Distributed:
Each node in the cluster has same role. There’s no question of failure & the data
set is distributed across the cluster but one issue is there that is the master isn’t
present in each node to support request for service.

Supports replication & Multi data center replication:


Replication factor comes with best configurations in Cassandra. Cassandra is
designed to have a distributed system, for the deployment of large number of
nodes for across multiple data centers and other key features too.

Scalability:
It is designed to r/w throughput, Increase gradually as new machines are added
without interrupting other applications.

Fault-tolerance:
Data is automatically stored & replicated for fault-tolerance. If a node Fails, then
it is replaced within no time.

MapReduce Support:
It supports Hadoop integration with MapReduce support.Apache Hive & Apache
Pig is also supported.

Query Language:
Cassandra has introduced the CQL (Cassandra Query Language). Its a simple
interface for accessing the Cassandra.
Data types in CQL:
These four built-in data types commonly used for columns in Cassandra Query
Language (CQL):

Text: Represents variable-length Unicode character string data. It's used for
storing textual data.

Int: Represents a 32-bit signed integer value. It's used for storing whole numbers
within a specific range.

Boolean: Represents a boolean value (true or false). It's used for storing binary
truth values.

Timestamp: Represents a point in time, typically in milliseconds since the Unix


epoch. It's used for storing temporal data.

Bigint: BIGINT stores 64-bit signed integers.

Double: It represents a 64-bit floating point and is used for integers.

Collection in Cassandra:
In Cassandra, Collections refer to data structures that allow the storage of
multiple values within a single column. These collections are useful for scenarios
where you need to handle multiple related pieces of data together. Cassandra
supports several collection types:

1. Set: A Set in Cassandra is an unordered collection of elements where each


element is unique. Sets do not allow duplicate elements within the collection.
They are useful when you need to store a collection of unique items.
Example: SET<text>.

2. List: A List is an ordered collection of elements where elements can be


duplicated. It maintains the insertion order, allowing access by index. Lists are
suitable when you need to store an ordered collection of items that might contain
duplicates.

Example: LIST<text>.

3. Map: A Map in Cassandra represents a collection of key-value pairs, where


each key is unique within the Map. It allows efficient lookup of values based on
keys. Maps are beneficial when dealing with data that has a key-value association.
Example: MAP<text, int>.

Using these collection types, you can embed complex data structures within a
single column of a Cassandra table.

CRUD operations in Cassandra:


1. The UPDATE operation is used to modify existing data in a table.

Here's an example:

Let's say we have a table called users with columns user_id, name, and email.

To update the email of a user with user_id = 123, the CQL query would look like
this:

Query: UPDATE users SET email = 'newemail@example.com' WHERE user_id =


123;

This query updates the email column for the user with user_id 123 to
'newemail@example.com'. You can modify multiple columns in a single UPDATE
query by including more SET clauses.

2. The DELETE operation is used to remove data from a table.

There are two types of DELETE operations in Cassandra: DELETE by primary key or
DELETE by specific columns.

DELETE by Primary Key:


Query: DELETE FROM users WHERE user_id = 123;

This query removes the entire row where user_id is 123 from the users table.

DELETE by Specific Columns:

To delete specific columns for a particular row, you'd use a query like this:

Query: DELETE email FROM user WHERE user_id = 123;

This query removes the email column's value for the user with user_id 123. The
row remains intact, but the email value is deleted.

3. The CREATE operation is used to create data from a table.

To create a table in Cassandra, you are use the CREATE TABLE statement.

Let's create a simple table called users with columns for user_id, name, and
email.

Query: CREATE TABLE users (user_id INT PRIMARY KEY, name TEXT,email TEXT);

This query creates a table named users with three columns: user_id, name, and
email. The user_id column is designated as the primary key.

The INSERT operation is used to insert the data from a table.

To insert data into the users table, you'd use the INSERT statement. For example:

Query: INSERT INTO users (user_id, name, email) VALUES (123, 'John Doe',
'john@example.com');

4. The READ operation is used to Reading data from a table:

Reading data from a table involves using the SELECT statement.

Here's an example:

To retrieve all columns for a specific user_id (let's assume user_id = 123), the
query would be:
Query: SELECT * FROM users WHERE user_id = 123;

This query fetches all columns (user_id, name, email) for the user with user_id
123.

You might also like