Thursday 3 December 2015

Cassandra Operations Part 1( Working with Key spaces )

Cassandra operations:
In this article we are going to create, alter and delete key spaces in Cassandra.  Key spaces are like data bases in Cassandra. In side of Key spaces we can able to create tables and we can load data into tables further
We are going to learn the following concepts from this article




For this first we will go to cqlsh mode and to connect with local Cassandra cluster as shown in below

Go to Cassandra installed location and to bin location and type. /cqlsh
Observe the below screen shot for better understanding



Creation of Key space

 Before going to create first we will check what the key spaces that present in Cassandra.  For this we can use DESC command to get the list of key spaces present in Cassandra.


From the above screen shot we can observe these steps
1)      This step will give the key spaces present in the Cassandra. If we observe there are 5 key spaces present as of now
2)      Creation of Key Space Sample_Cassandra   as shown in step 2 with options Replication.
In this replication we have to mention the class name and replication factor
3)      Checking either Sample_Cassandra created or not using DESC command once again



Altering Key space:

We can alter the already existing key space with this Command Alter.
In this current example we are Altering the Sample_Cassandra that we created in the above step           

If we observe the above screen shot we are altering schema with replication factor value as ‘3 ‘
So we can check the modified schema by seeing key space information as mention below
Just as similar to SQL command in Cassandra also supports same query language.

So to see the keyspace information we can see like executing command as below
Query: Select * from system.shema_keyspaces;
From the below screen shot we can able to find out the Schema details of key spaces present in the Cassandra.

In the above screen shot we can check the keyspaces schemas present in the Cassandra. Total it returned 6 rows each represents one key space.

Dropping Key space:

We can drop key space present in Cassandra using Drop command

From the above screen shot we will observe the following
1)      Dropping Keyspace Sample_Cassandra
2)      Checking either schema dropped or not using DESC command



Next article we will see Table operations in Cassandra 

No comments:

Post a Comment