TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Cassandra Collections

Cassandra Collections for beginners and professionals with topics on architecture, relational vs no sql database, data model, cql, cqlsh, keyspace operations, table operations, installation, collections etc.

<< Back to CASSANDRA

Cassandra Collections

Cassandra collections are used to handle tasks. You can store multiple elements in collection. There are three types of collection supported by Cassandra:

  • Set
  • List
  • Map

Set Collection

A set collection stores group of elements that returns sorted elements when querying.

Syntax:

Create table table_name
(
id int,
Name text,
Email set<text>,
Primary key(id)
); 

Example:

Let's take an example to demonstrate set collection. Create a table "employee" having the three columns id, name and email.

Cassandra Collection 1

The table is created like this:

Cassandra Collection 2

Insert values in the table:

INSERT INTO employee (id, email, name)   
VALUES(1, {'ajeetraj4u@gmail.com'}, 'Ajeet');  
INSERT INTO employee (id, email, name)   
VALUES(2,{'kanchan@gmail.com'}, 'Kanchan'); 
INSERT INTO employee (id, email, name)   
VALUES(3, {'kunwar4u@gmail.com'}, 'Kunwar');

Output:

Cassandra Collection 3

List Collection

The list collection is used when the order of elements matters.

Let's take the above example of "employee" table and a new column name "department" in the table employee.

Cassandra Collection 4

Now the new column is added. Insert some value in the new column "department".

Cassandra Collection 5

Output:

Cassandra Collection 6

Map Collection

The map collection is used to store key value pairs. It maps one thing to another. For example, if you want to save course name with its prerequisite course name, you can use map collection.

See this example:

Create a table named "course".

Cassandra Collection 7

Now table is created. Insert some data in map collection type.

Output:

Cassandra Collection 8




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf