Cassandra Data Types | Built-in, Collection, User-defined

FREE Online Courses: Click, Learn, Succeed, Start Now!

1. Objective

In our previous Cassandra article, we went through the CURD operations in Cassandra. In this article, we will study the Cassandra Data Types. Moreover, in CQL data types we will see 3 different types of data types Built-in, collection, and user-defined data types.  

So, let’s begin Cassandra Data Types.

Cassandra Data Types

Cassandra Data Types | Built-in, Collection, User-defined

2. What are the Cassandra Data Types?

Data Types usually signify the type of variables assigned in a program. We have studied many data types in other programming languages. For example int, char, float etc. In Cassandra query language, there are many data types.

These Cassandra Data Types include built-in, collection and user-defined data types. The user can choose any of them as according the requirement of the program.
Learn Cassandra Data Model | How Cassandra Stores Data

3. Types of Cassandra Data Types

Following are the 3 Cassandra Data Types, let’s discuss them one by one:

a. Built-In Data Type

These Cassandra data types are basically pre-defined in Cassandra. The user can refer the variables to any of them. There are many built-in data types in Cassandra data types. Some of them are:

Cassandra Data Types | Built-in, Collection, User-defined

Cassandra Data Types- Built-in Data Types

Prepare yourself for Cassandra Interview

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

i. boolean
This Cassandra data type is used booleans. They represent two values, true or false. We use this for applications or variables involving just two values.

ii. blob
This Cassandra data type represents the arbitrary bytes. These arbitrary bytes include any kind of variable used to represent an arbitrary variable.
Let’s discuss Cassandra Architecture a Complete Guide

iii. ascii
This Cassandra data type is used for strings i.e. words and sentences. This represents the ASCII character string. The ASCII is basically an identifier for different characters. We store the value of the variable as ASCII code of the value.

iv. bigint
This Cassandra data type is used for 64 bit signed long integer. This data type stores a higher range of integers as compared to int. In this data type 64 bit signed represents a value from -(2^32) to +2^32 roughly.

v. Counter
This Cassandra data type is used for integers. It represents a counter column. These columns are a part of the rows, which in turn are part of the column family. These contain numeric values, containing the number of columns.

vi. decimal
This data type is used for Example-integers. This is a basic data type used in approximately every language.

vii. double
It is used for integers. It represents a 64-bit floating point. These include a number with decimal points as well. Example 5.883, 94.2 etc.
Explore Cassandra Applications

viii. float
It is used for numbers. It represents a 32-bit floating point. This contains numbers in a lesser range than double. It represents values with a decimal point. Example 4.333, 45.23523 etc..

ix. inet
This is used to represent an IP address. The IP address of any system includes both numeric and characters. These numbers won’t require in any arithmetic operation. Therefore, we treat them as a character. In other words, this data type is used for strings or characters.

x. int
They represent 32-bit signed integers. This is a low range version of big int. The signed integer represents numbers both negative and positive. The range of the number that int supports lie from -2^16 to 2^16 roughly.

xi. text
It is used for strings. It represents UTF8 encoded string. UTF 8 is a variable with character encoding. This basically encodes all the valid points in Uni-code using one to four 8-bit types.
Let’s revise 9 Cassandra Shell Commands – You Must Know

xii. varchar
It is used for strings. It represents UTF8 encoded string.  This basically describes a variable or arbitrary character. It is used to satisfy the UTF 8 as discussed in the above data type

xiii. timestamp
It represents a timestamp. It consists of Cassandra collections of integers and strings both. This timestamp basically represents the time of creation. We can use a lot of formats for the timestamp. This format includes the date, year, month, time, and also the meridian position for some time.
The formats are:
yyyy-mm-dd HH:mm
yyyy-mm-dd HH:mm:ss

Example: If the user wants time say, 15 February 1995, 02:15 AM at GMT. The timestamp would be: 1995-02-15  02:15+0000.
All the meridian are represented as 4 digit number. For India, the number is +0530.

xiv. variant
It is used for integers.  It represents an arbitrary-precision integer.
After going through all the data types, we will go through an example covering all the data type. Let us make a table and illustrate the data types using this table.

Have a look at mostly used Cassandra Terminologies

cqlsh:keyspace1>CREATE TABLE datatypes(
type1 boolean,
type2 blob,
type3 ascii,
type4 bigint,
type5 counter,
type6 decimal,
type7 double,
type8 float,
type9 inet,
type10 int,
type11 <text, varchar>,
type12 timestamp,
type13 variant,

Now, go through the table below to know about the data storage in the data types.

NameData typeData stored
Type2Blob//binary large objects
Type3ASCII65(A), 97(a) etc
Type4Bigint-2^32 to +2^32 (only integers)
Type7Double-2^32 to +2^32 (all real numbers)
Type8Float-2^16 to +2^16 (all real numbers)
Type9InetAXHFD327864SAF etc
Type10Int-2^16 to +2^16 (only integers)
Type11Text, varchar79-*($wkjh#$ etc
Type12Timestamp2018-05-18 03:21+0530 etc
Type13Variant123,34,2213 etc

Let’s discuss Cassandra User Defined Types

b. Collection Data Type

This data type use for collective data used in a single variable. Cassandra Query Language provides three type of collection data type.

Cassandra Data Types

Cassandra Data Types- Collection Data Type

i. List
This Cassandra data type represents a collection of one or more elements in a table.

ii. Map
This data type represents a collection of key-value pairs.

iii. Set
This Cassandra data type represents a collection of one or more sorted elements in a table.
Let’s revise 5 Important Cassandra Features

c. User-Defined Data Type

CQL enables the user to create their own data type as per their requirement. After creating data type and fields in it the user can alter, verify and even drop a field or the whole data type.

So, this was all about Cassandra Data Types. Hope you like our explanation of data types in Cassandra CQL.

4. Conclusion

Hence, in this Cassandra Data Types tutorial, we studied 3 major data types: Built-in, Collection, and User-Defined Cassandra Data Types. Moreover, we saw many data types in Built-in Data Type.

At last, we discussed Cassandra set data type, Cassandra map data type. In the next article, we will go through Collection Data Type in a detailed manner.

Furthermore, for any query, feel free to ask through the comment section.
See also – HBase vs Cassandra – Major Difference & Similarities in 2018
For reference

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

follow dataflair on YouTube

1 Response

  1. rohan nirer says:

    Hi, is it possible to a comma separated values in casssandra.

Leave a Reply

Your email address will not be published. Required fields are marked *