Main Content

Convert CQL Data Types to MATLAB Data Types Using Apache Cassandra Database C++ Interface

When you import data into MATLAB® using the Apache® Cassandra® database C++ interface, the partitionRead and executecql functions convert the Cassandra Query Language (CQL) data types to MATLAB data types. When you export from MATLAB into a Cassandra database, the upsert function converts MATLAB data types to CQL data types. This table describes the CQL data types and shows their corresponding MATLAB data types for data import and export.

CQL Data TypeCQL Data Type DescriptionData Type of MATLAB Table Variable for Data ImportData Type of MATLAB Table Variable for Data Export

ascii

US-ASCII character string

string

char, string, or cell array of character vectors

bigint

64-bit signed long integer

int64

  • double

  • single

  • int8

  • int16

  • int32

  • int64

  • uint8

  • uint16

  • uint32

  • uint64

  • logical

blob

Arbitrary bytes (no validation)

uint8

cell array of numeric vectors

boolean

true or false

logical

  • double

  • single

  • int8

  • int16

  • int32

  • int64

  • uint8

  • uint16

  • uint32

  • uint64

  • logical

counter

Distributed counter value (64-bit long integer)

int64

Not supported by the upsert function

date

Value is a date with no corresponding time value. Cassandra encodes the date as a 32-bit integer representing days since epoch (January 1, 1970).

datetime array without the time component and time zone

datetime array, char, string, or cell array of character vectors

decimal

Variable-precision decimal

string

  • string

  • cell array of character vectors

  • double

  • single

  • int8

  • int16

  • int32

  • int64

  • uint8

  • uint16

  • uint32

  • uint64

  • sym

double

64-bit IEEE®-754 floating point

double

  • double

  • single

  • int8

  • int16

  • int32

  • int64

  • uint8

  • uint16

  • uint32

  • uint64

  • logical

float

32-bit IEEE-754 floating point

single

  • double

  • single

  • int8

  • int16

  • int32

  • int64

  • uint8

  • uint16

  • uint32

  • uint64

  • logical

inet

IP address string in IPv4 or IPv6 format

string

char, string, or cell array of character vectors

int

32-bit signed integer

int32

  • double

  • single

  • int8

  • int16

  • int32

  • int64

  • uint8

  • uint16

  • uint32

  • uint64

  • logical

list<type>

Collection of one or more ordered elements (for example, [literal, literal, literal])

Array of data types, one for each item in the collection.

For example, if a Cassandra database table column has the list<int> data type, then each row in the MATLAB table contains an array of int32 data types. In this case, the data type of the MATLAB table variable is a cell array of arrays.

Cell array of vectors, where each vector is compatible with the type of the list.

For example, if the Cassandra database table contains list<int>, then the MATLAB table must contain a cell array of numeric vectors.

map<keyType,valueType>

JSON-style array of literals (for example, { literal : literal, literal : literal, ...})

An n-by-2 MATLAB table where n is the number of key-value pairs in the map. The first variable Keys has the keys of the map. The data type for this variable depends on the key type defined for the map. Similarly, the Values variable has the values that correspond to each key. The data type for the Values variable depends on the value type defined for the map.

For example, if a Cassandra database table column has the map<text,double> data type, then the partitionRead and executecql functions convert this data type into a MATLAB table. The table has the Keys variable as string scalars and the Values variable as a double array. In this case, the data type of the MATLAB table variable is a cell array of tables.

Cell array of tables, where each table contains the Keys and Values variables.

The data types of these two variables are compatible with the data types of the keys and values of the Cassandra database map.

For example, if the Cassandra database table contains map<int,text>, then the MATLAB table must contain a cell array of tables, where each table has a Keys variable that is numeric and a Values variable that is a string.

set<type>

Collection of one or more elements (for example, {literal, literal, literal})

Array of data types, one for each item in the collection.

For example, if a Cassandra database column has the set<float> data type, then each row in the resulting MATLAB table contains an array of single values. In this case, the data type of the MATLAB table variable is a cell array of arrays.

Cell array of vectors, where each vector is compatible with the type of the collection.

For example, if the Cassandra database table contains set<int>, then the MATLAB table must contain a cell array of numeric vectors.

smallint

2-byte integer

int16

  • double

  • single

  • int8

  • int16

  • int32

  • int64

  • uint8

  • uint16

  • uint32

  • uint64

  • logical

text

UTF-8 encoded string

string

char, string, or cell array of character vectors

time

Cassandra database encodes this value as a 64-bit signed integer that represents the number of nanoseconds since midnight.

duration array

duration array, char, string, or cell array of character vectors

timestamp

Date and time with millisecond precision, encoded as 8 bytes since epoch (January 1, 1970)

datetime array with the date component and time zone as UTC or GMT

datetime array, char, string, or cell array of character vectors

timeuuid

Version 1 UUID only

string

char, string, or cell array of character vectors

tinyint

1-byte integer

int8

  • double

  • single

  • int8

  • int16

  • int32

  • int64

  • uint8

  • uint16

  • uint32

  • uint64

  • logical

tuple<Type1,...,TypeN>

Group of unnamed but typed fields

A 1-by-n MATLAB table, where n is the number of fields in the tuple. The variable names are Var1, Var2, Var3, and so on, until Var(n). The data type of each variable depends on the Cassandra data types defined in the tuple.

For example, if a Cassandra database column has the tuple<text,smallint,timestamp> data type, then the partitionRead and executecql functions convert this data type into a MATLAB table. The table has the Var1 variable as a string array, Var2 as an int16 array, and Var3 as a datetime array. In this case, the data type of the MATLAB table variable is a table.

MATLAB table.

The position of each variable in the table determines which field the variable maps to in the tuple. The first variable in the table maps to the first field in the tuple, the second variable maps to the second field, and so on.

For example, if the Cassandra database table contains tuple<int,text>, then the MATLAB table must contain a table where the first variable is numeric and the second variable is a string.

user-defined type (UDT)

Group of named fields

A 1-by-n MATLAB table, where n is the number of fields in the UDT. Variable names match the field names of the UDT. The data type of each variable depends on the Cassandra data types defined in the UDT. The data type of the MATLAB table variable is a table.

MATLAB table.

The names of the variables in the table must match the names of the UDT fields. The data type of each variable in the table must be compatible with the Cassandra data type of the corresponding UDT field.

uuid

UUID in standard UUID format

string

char, string, or cell array of character vectors

varchar

UTF-8 encoded string

string

char, string, or cell array of character vectors

varint

Arbitrary-precision integer

string

  • string

  • cell array of character vectors

  • double

  • single

  • int8

  • int16

  • int32

  • int64

  • uint8

  • uint16

  • uint32

  • uint64

  • sym

Note

For the CQL data type, if the data type is a collection (for example, list, map, and so on), then the value contains angle brackets (<>). These brackets surround the data types of the items in the collection. For details about valid Cassandra data types, see CQL Data Types.

See Also

| |

Related Topics

External Websites