Prerequisite – User Defined Type (UDT) in Cassandra
In this article, we will discuss different types of data types in Cassandra which is used for various purpose in Cassandra such that in data modeling, to create a table, etc.
Basically, there are 3 types of data type in Cassandra. Lets have a look.
Now, here we are going to discuss the Built-in data type in Cassandra.
Built-in Data Type:
It is a pre-defined data type in Cassandra. We can directly use by simply giving data type names as per need. There are many Built-in Data types in Cassandra. let’s discuss one by one.
It is a data type that represents two values, true or false. So, we can use such type of data type where we need just two values.
true or false
CREATE TABLE table_name( field_name1 Boolean, ... );
It is used for binary large objects such that audio, video or other multimedia and sometimes binary executable code stored as a blob.
binary large objects
CREATE TABLE table_name( field_name1 blob, ... );
It is used for strings type such that words and sentences. It represents the ASCII value of the character. For example, for ‘A’ ASCII value is 65. so, it will store its ASCII value.
65 for A, 97 for a, etc.
CREATE TABLE table_name( field_name1 ascii, ... );
It is used for 64 bit signed long integer. Basically it is used for high range of integer which represents a value from -(2^32) to +(2^32) roughly.
only for integers -(2^32) to +(2^32)
CREATE TABLE table_name( field_name1 bigint, ... );
It is used for integers and represents a counter column. These columns part of the row which represents column family which basically contains numeric values, containing the number of columns.
1, 2, 3... (integer)
CREATE TABLE table_name( field_name1 counter, ... );
It is used to save integer and float values. In Decimal data type is important to note when we tried to save decimal value such as .907 ( dot 907), it will give an error “no viable alternative at input ‘.’ (…DecimalValue) Values ( 1, [.]…)”. If we need to save decimal like that then start with zero e.g 0.907.
10.45, 1, -1, 0.32...
CREATE TABLE table_name( field_name1 DECIMAL, ... );
It is used for integers which represents a 64 bit floating point. It include a number with a decimal points. for example: 5.838, 10.45 etc.
10.4556, 3.566, 0.5875 etc.
CREATE TABLE table_name( field_name1 double, ... );
It is used for numbers which represents a 32-bit floating point. It represents a number values with a decimal point. for example : 6.254, 5.23 etc.
5.423, 2.31, 3.12...[32 bit floating point]
CREATE TABLE table_name( field_name1 float, ... );
It is used to represent an IP address that includes both numeric and characters. basically It Represents an IP address, IPv4 or IPv6. For example, 188.8.131.52 for such type address we can use inet data type.
184.108.40.206 ...[IP address, IPv4 or IPv6]
CREATE TABLE table_name( field_name1 inet, ... );
It is used to Represents 32-bit signed integers. It represents both positive and negative numbers. The range of int lies from -(2^16) to +(2^16) [only integers].
24, 907, -9, ...
[Represents 32-bit signed int -(2^16) to +(2^16) [only integers]]
CREATE TABLE table_name( field_name1 int, ... );
It is used to store string type which Represents UTF8 encoded string. It encodes all valid points in Uni-code by using 1 bit to four 8 bit types in Cassandra.
Ashish, rana, ...[Represents UTF8 encoded string]
CREATE TABLE table_name( field_name1 text, ... );
It is used to store arbitrary string which represents UTF8 encoded string.
Ashish, rana, a$#34, A67dgg...
[arbitrary string, Represents UTF8 encoded string]
CREATE TABLE table_name( field_name1 varchar, ... );
It is used to represents a timestamp which is very helpful to store the exact time format value of timestamp. For example, if we want to store 15 dec 1995 at 4:00 AM then timestamp would be:
1995-12-15 04:00 +0530
Here +0530 is represents meridian for India.
[formats: yyyy-mm-dd HH:mm or yyyy-mm-dd HH:mm:ss]
CREATE TABLE table_name( field_name1 timestamp, ... );
It is used to represents arbitrary-precision integer such that 124, 24, 1, 5468 etc.
1, 24, 07, 897, 4568, etc.
CREATE TABLE table_name( field_name1 variant, ... );
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Collection Data Type in Apache Cassandra
- Overview of Data modeling in Apache Cassandra
- Difference Between Apache Kafka and Apache Flume
- Difference between Apache Hive and Apache Spark SQL
- Apache Cassandra tools
- Introduction to Apache Cassandra
- Apache Cassandra (NOSQL database)
- Architecture of Apache Cassandra
- Concept of indexing in Apache Cassandra
- Five main benefits of Apache Cassandra
- SSTable in Apache Cassandra
- Node in Apache Cassandra
- Altering a table to add a collection data type in Cassandra
- Updating MAP collection data type in Cassandra
- Static type using batch in Cassandra
- Overview of User Defined Type (UDT) in Cassandra
- Static type in Cassandra
- Tuple Type in Cassandra
- Counter Type in Cassandra
- Data Manipulation in Cassandra
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.