Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

2/21/2018

Reading time:1 min

Brief Introduction to Cassandra Query Language (CQL) - Cassandra Tutorial | Intellipaat.com

by John Doe


 « Previous

 Next »
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 accessBelow 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 SpaceALTER KEYSPACE ” demodb ” WITH REPLICATION = { ‘class’ : ‘SimpleStrategy’,‘replication_factor’ : 2}; 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 CassandraLet’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: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 >02.) Get books from same author Queries for business point of view3.) Get Customer liking per geographic location4.) Most liked categorySo in order to incorporate this quicker we need to de-normalize data and create new column families.A detailed understanding of Apache Cassandra is available in this blog post for your perusal!
 « Previous

 Next »

Illustration Image

« Previous

Next »

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};

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:

img 6

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

A detailed understanding of Apache Cassandra is available in this blog post for your perusal!

« Previous

Next »

Related Articles

windows
cassandra
tutorial

Install Cassandra on Windows 10: Tutorial With Simple Steps

Vladimir Kaplarevic

12/2/2023

cassandra
tutorial

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

cassandra