• Articles
  • Tutorials
  • Interview Questions

Introduction to Cassandra Query Language (CQL)

What is CQL?

CQL is simple api mean for accessing Cassandra.CQL adds an abstraction layer that hides implementation details of this structure and provides native syntaxes for collections and other common encodings.

Common ways to access CQL are:
• Start cqlsh, the Python-based command-line client, on the command line of a Cassandra node.
• For developing applications, use one of the C#, Java, or Python open-source drivers.
• Use the set_cql_version Thrift method for programmatic access
Below are common operation we can do with CQL

1. Creating and using key space:
cqlsh> CREATE KEYSPACE demodb WITH REPLICATION = { ‘class’ :
‘NetworkTopologyStrategy’, ‘datacenter1’ : 3 };
USE demodb;

2. Alter Key Space
ALTER KEYSPACE ” demodb ” WITH REPLICATION = { ‘class’ : ‘SimpleStrategy’,
‘replication_factor’ : 2};

Certification in Bigdata Analytics

3. Create Table
CREATE TABLE emp ( empID int, deptID int, first_name varchar,last_name varchar, PRIMARY KEY (empID, deptID));

4. Insert into table
INSERT INTO emp (empID, deptID, first_name, last_name) VALUES (104, 15, ‘jane’, ‘smith’);

5. Select query Select * from emp;
Scaling online library with Cassandra
Let’s talk about a very simple example of online books library. In relation database the system will have multiple normalized schemas. Few of very important one are described below:

CQL tutorial

As with introduction of “free users” and “unlimited books at my dispose” features in online book library, popularity of app increased to great extend .Resultant was flood of customer data. These made RDBMS setup unstable and business decided to go with Cassandra to mitigate the issue.
Before designing Cassandra table we need to find out all possible queries which key space shall support.

Most fired queries would be:
1. Get books of category with availability >0
2. Get books from same author Queries for business point of view
3. Get Customer liking per geographic location
4. Most liked category
So in order to incorporate this quicker we need to de-normalize data and create new column families.

img 7

Course Schedule

Name Date Details
Big Data Course 30 Nov 2024(Sat-Sun) Weekend Batch View Details
07 Dec 2024(Sat-Sun) Weekend Batch
14 Dec 2024(Sat-Sun) Weekend Batch

About the Author

Technical Research Analyst - Big Data Engineering

Abhijit is a Technical Research Analyst specialising in Big Data and Azure Data Engineering. He has 4+ years of experience in the Big data domain and provides consultancy services to several Fortune 500 companies. His expertise includes breaking down highly technical concepts into easy-to-understand content.