Updated March 24, 2023
Introduction to Cassandra Data Types
Cassandra Data Types contains a rich set of data types, including native types, collection types, user-defined types, tuple types, and custom types. These data types are important and are used to reserve the memory to store the data as per the input type of data. This helps prevent errors and enhance the readability of the input data at the compiler as well as the programmer level. In the case of databases, When a datatype is specified for a column in a table then only that set of data and values can be stored.
Cassandra Data Types
Below are some of the major data types:
1. Types of Cassandra Native Data Types
Cassandra Query language contains different types of data types:
The table contains several rows and the following three columns: CQL Type, Constants, and Description.
- ascii: The first CQL type is ASCII. Its corresponding constants are strings and its description is that it is US-ASCII character string.
- bigint: The second CQL type is bigint. Its corresponding constants are integers and its description is that it is 64-bit signed long.
- blob: The third CQL type is a blob. Its corresponding constants are blobs and its description is that it contains arbitrary bytes (no validation) and expressed as hexadecimal.
- boolean: The fourth CQL type is boolean. Its corresponding constants are booleans and its description is that it is either true or false.
- counter: The fifth CQL type is counter. Its corresponding constants are integers and its description is that it is a distributed counter value (64-bit long).
- decimal: The sixth CQL type is decimal. Its corresponding constants are integers and floats and its description is that it is a variable-precision decimal.
- double: The seventh CQL type is double. Its corresponding constants are integers and its description is that it is a 64-bit IEEE-754 floating-point.
- float: The eighth CQL type is afloat. Its corresponding constants are integers and floats and its description is that it is a 32-bit IEEE-754 floating-point.
- inet: The ninth CQL type is inet. Its corresponding constants are strings and its description is that it is an IP address string in IPv4 or IPv6 format*.
- int: The tenth CQL type is int. Its corresponding constants are integers and its description is that it is a 32-bit signed integer.
- list: The eleventh CQL type is the list. Its corresponding constant is n/a and its description is that it is a collection of one or more ordered elements.
- map: The twelfth CQL type is the map. Its corresponding constant is n/a and its description is that it is a JSON-style array of literals: { literal: literal, literal: literal… }.
- set: The thirteenth CQL type is set. It is corresponding constant n/a and its description is that it as a collection of one or more elements.
- text: The fourteenth CQL type is text. Its corresponding constants are strings and its description is that it is a UTY-8 encoded string.
- timestamp: The fifteenth CQL type is a timestamp. Its corresponding constants are integers and strings and its description is that it includes as a date plus time and is encoded as 8 bytes since epoch.
- uuid: The sixteenth CQL type is uuid. Its corresponding constants are uuids and its description is that it is a UUID in standard UUID format.
- timeuuid: The seventeenth CQL type is timeuuid. Its corresponding constants are uuids and its description is that it is a type 1 UUID only (CQL 3).
- varchar: The eighteenth CQL type is varchar. Its corresponding constants are strings and its description is that it is a UTG-8 encoded string.
- varint: The nineteenth CQL type is variant. Its corresponding constants are integers and its description is that it is an arbitrary-precision integer.
2. Types of Collection Data Types
CQL supports 3 types of collections: Maps, Sets, and Lists.
- Map: Map is a sorted set of key-value pairs, where keys are unique and the map is sorted by its keys.
- Sets: A set is a sorted collection of unique values.
- Lists: A list is a sorted collection of non-unique values where elements are ordered by there position in the list.
3. User-Defined Data Types
CQL supports the definition of user-defined types (UDT for short). Such a type can be created, modified and removed using the create_type_statement, alter_type_statement and drop_type_statement
4. Tuple Data Types
Cassandra Query Language also supports tuple data types. These tuple data times consist of elements or parameters that can comprise of different data types. Tuples can be either customized data type or anonymous user-defined data type. A tuple is always in the frozen state and hence it is not possible to modify the elements of a tuple partially or individually without actually updating the whole tuple.
Conclusion
These Different sets of data types in CQL are used to read the input data, allocate the memory to be reserved for processing the data and then compile the data to use it as per the user requirement. Hence, these data types intend to inform the compiler regarding how the data is going to be used. It also defines the operations that can be done using the data.
Recommended Articles
This is a guide to Cassandra Data Types. Here have discuss the introduction to Cassandra data types along with the top 4 data types. You may also have a look at the following articles to learn more –