Cassandra Datatype
Cassandra Data Type & Data Expiration
Cassandra Data Types:
In Cassandra the Data Types are majorly divided into three categories,
- Built-in Data Types.
- User-defined Data Types.
- Collection Types.
Built-In Data Types:
- Boolean:
The booleans data type is utilized in Cassandra for defining true or false, the two values they represent. This is used for applications or variables with only two possible values.
- Blob:
Arbitrary bytes are represented by this Cassandra data type. These arbitrary bytes contain any variable that is utilised for arbitrary variable representation.
- Ascii:
Strings, such as words and phrases, are stored in this Cassandra data type. The ASCII character string is represented by this.
- Counter:
This data type of Cassandra is used for integer applications. The counter column is represented. The columns belong to the rows that are members of the column family in turn. These include numerical values with the number of columns.
- Decimal:
For example-integrations this data type is utilised. This is a basic type of information used in about every language.
- Double:
This is for integer applications. It is a floating point of 64 bits. These also contain a number of decimal points. Example 9.443, 92.8 etc.
- Float:
Regarding numbers, it is applied. It is a floating point of 32-bit. Numerals are less than twice. This includes numbers. It indicates a decimal point value. Example 8.555, 79.1323523 and so on.
- Inet:
It can be used to display an IP address. Numbers and characters are included in the IP address of each system.
- Int:
These are 32-bit integer identifiers. It's a large int low-speed variant. The number signed shows both positive and negative numbers. The number supported by int is about -2^16 to 2^16.
- Text:
This type is used for string type functions and variables. The encoded UTF8 string is shown. UTF 8 is the encoding variable. This codes all acceptable Uni-code points with one to four 8-bit kinds.
- Timestamp:
Time stamp formats:
yyyy-mm-dd HH:mm
yyyy-mm-dd HH:mm:ss
This datatype represents timestamp. It is made up of Cassandra collections of integers and strings. This timestamp is essentially the moment of creation. For the timestamp, we may use a variety of forms.
Cassandra can handle a variety of data types. The table below lists data types, as well as their constants and descriptions.
Data Type | Constants | Description |
ascii | strings | Represents ASCII character string |
bigint | bigint | Represents 64-bit signed long |
blob | blobs | Represents arbitrary bytes |
Boolean | booleans | Represents true or false |
counter | integers | Represents counter column |
decimal | integers, floats | Represents variable-precision decimal |
double | integers | Represents 64-bit IEEE-754 floating point |
float | integers, floats | Represents 32-bit IEEE-754 floating point |
inet | strings | Represents an IP address, IPv4 or IPv6 |
int | integers | Represents 32-bit signed int |
text | strings | Represents UTF8 encoded string |
timestamp | integers, strings | Represents a timestamp |
timeuuid | uuids | Represents type 1 UUID |
uuid | uuids | Represents type 1 or type 4 |
varchar | strings | Represents uTF8 encoded string |
varint | integers | Represents arbitrary-precision integer |
User-defined datatypes:
Cqlsh offers users the opportunity to create their own sorts of information. The instructions used for user-defined data types are listed below.
- CREATE TYPE - Defines user-defined data type.
- ALTER TYPE - Changes the user's data type.
- DROP TYPE - Drops a data type defined by the user.
- DESCRIBE TYPE - Specifies a datatype created by users.
- DESCRIBE Kinds – User specified types of data are described.
Collection Types:
The collection data types also are available through the Cassandra Query Language. A list of Collections accessible in CQL is shown in the table below.
Collections | Description |
map | A map includes a set of key value pairs. |
set | A set consists of one or even more components. |
list | A list is an assembly of one or more components arranged |
Cassandra Automatic Data Expiration using Time to Live (ttl):
The capability of Cassandra allows data to be expired automatically.
You must provide 'ttl' in seconds during data insertion. The number 'ttl' is the period for the data to live. Data will be deleted automatically after this certain length of time.
For instance, during insertion give the ttl value for 110 seconds. Data are automatically deleted after 110 seconds. When the data is expired, it is indicated with a grave.
There is a grave for a period of grace. Once the data has expired, following a compaction procedure the data is deleted automatically.
Syntax:
Insert into KeyspaceName.TableName(ColumnNames) values(ColumnValues)
using ttl TimeInseconds;
Example
This is the screenshot where data is entered into a student table with a 110-second ttl value.
insert into Firm.Employee(id,name,dept,salary)
values(5,'Ram','IT’,40000) using ttl 110;
Here is a screenshot of the automated expiration of the data after 110 seconds and removal.