Cassandra Data Types | Built-in, Collection, User-defined
Keeping you updated with latest technology trends, Join DataFlair on Telegram
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.
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:
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.
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
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.
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.
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.
This data type is used for Example-integers. This is a basic data type used in approximately every language.
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
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..
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.
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.
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
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
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:
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.
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.
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.
|Name||Data type||Data stored|
|Type2||Blob||//binary large objects|
|Type3||ASCII||65(A), 97(a) etc|
|Type4||Bigint||-2^32 to +2^32 (only integers)|
|Type7||Double||-2^32 to +2^32 (all real numbers)|
|Type8||Float||-2^16 to +2^16 (all real numbers)|
|Type10||Int||-2^16 to +2^16 (only integers)|
|Type11||Text, varchar||79-*($wkjh#$ etc|
|Type12||Timestamp||2018-05-18 03:21+0530 etc|
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.
This Cassandra data type represents a collection of one or more elements in a table.
This data type represents a collection of key-value pairs.
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.
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