/    /  Cassandra – Data Types

Cassandra – Data Types

In this tutorial, we will learn about the Data Types in Cassandra CQL language. DataTypes generally define the type of data a column can hold along with their own significance. CQL language supports the below list Data types:

1. Native Types
2. Collection Types
3. User-defined Types
4. tuple types

TYPECONSTANTSDESCRIPTION
asciistringASCII character string
bigintinteger64-bit signed long
blobblobArbitrary bytes
booleanbooleanEither true or false
counterintegerCounter column
dateinteger, stringA date (with no corresponding time value).
decimalinteger, floatVariable-precision decimal
doubleinteger float64-bit IEEE-754 floating point
floatinteger, float32-bit IEEE-754 floating point
inetstringAn IP address
intinteger32-bit signed int
smallintinteger16-bit signed int
textstringUTF8 encoded string
timeinteger, stringA time with nanosecond precision
timestampinteger, stringA timestamp with millisecond precision.
timeuuiduuidVersion 1 UUID
tinyintinteger8-bit signed int
uuiduuidA UUID (of any version)
varcharstringUTF8 encoded string
varintintegerArbitrary-precision integer

Collection Types

There are 3 types of collection datatypes :

1. Maps

Map is a set of Key-value pairs.Where keys are unique.

Example:

CREATE TABLE Blog (
id int PRIMARY KEY,
data map <text, text>
);

2. Sets

Set is collection of unique values.

Example:

CREATE TABLE Blog (
ID int PRIMARY KEY,
tags set<text>
);

3. Lists

List is a collection of non-unique values which can be ordered with their position.

Example:

CREATE TABLE plays (
id text PRIMARY KEY,
Name text,
posts list<int>
)

User Defined Type

UDT can be created, modified and removed using below commands.

– CREATE TYPE
– ALTER TYPE
– DROP TYPE

Example:

CREATE TYPE Blogger (
city text,
Name text,
Phone int
)

CREATE TYPE Blogs (
ID int,
Blogname text,
Address map<text, Blogger>
)

Tuples

Tuples are a set of different types of elements.

Example:

CREATE TABLE Blogs (
BlogId text,
BlogType tuple<int, text>
)