Tuple and user-defined types
- Last Updated: July 25, 2025
- 2 minute read
- DataDirect Connectors
- ODBC
- Apache Cassandra 8.0
- Documentation
The driver supports Tuple and user-defined complex types which were introduced with Apache Cassandra 2.1. As long as there are no complex types nested in either the Tuple or user-defined types, the driver normalizes Tuple and user-defined types by flattening them into a relational version of the native Cassandra table. Take for example the following Cassandra table:
CREATE TABLE agents1 (
agentid int PRIMARY KEY,
email varchar,
contact tuple<varchar,varchar,varchar>);
The following AGENTS1 table is a tabular
representation of the native Cassandra table with data included.
| AGENTID (primary key) |
CONTACT | |
|---|---|---|
| int | varchar | tuple<varchar, varchar, varchar> |
272 |
barronr@email.com |
tv
|
564 |
rothm@email.com |
radio
|
For the relational version of agents1, all
fields are retained as separate columns, and columns with primitive types (AGENTID and EMAIL)
correspond directly to columns in the native table. In turn, tuple fields are flattened
into columns using a <tuplename>_<ordinal>
naming pattern. The driver normalizes agents1 in the
following manner.
| AGENTID (primary key) |
CONTACT_1 | CONTACT_2 | CONTACT_3 | |
|---|---|---|---|---|
| int | varchar | varchar | varchar | varchar |
272 |
barronr@email.com |
tv |
newspaper |
blog
|
564 |
rothm@email.com |
radio |
tv |
magazine
|
A SQL command would take the following form:
INSERT INTO AGENTS1 (AGENTID,EMAIL,CONTACT_1,CONTACT_2,CONTACT_3)
VALUES (839,'gonzalesn@email.com','radio','tv','magazine')
The driver also flattens user-defined types when normalizing native Cassandra
tables. In the following example, the native Cassandra agents2 table incorporates the user-defined address type.
CREATE TYPE address (
street varchar,
city varchar,
state varchar,
zip int);
CREATE TABLE agents2 (
agentid int PRIMARY KEY,
email varchar,
location frozen<address>);
The following AGENTS2 table is a tabular
representation of the native Cassandra table with data included.
| AGENTID (primary key) |
LOCATION | |
|---|---|---|
| int | varchar | address<street: varchar, city: varchar, state: varchar, zip: int> |
095 |
barronr@email.com |
street: 1551 Main
Street
|
237 |
rothm@email.com |
street: 422 First
Street
|
As with the previous example, all fields are retained as separate columns in
the relational version of the table, and columns with primitive types (agentid and email)
correspond directly to columns in the native table. Here a <columnname>_<fieldname> naming pattern is used to flatten the
fields of the user-defined address type into columns. The driver normalizes agents2 in the following manner.
| AGENTID (primary key) |
LOCATION_STREET | LOCATION_CITY | LOCATION_STATE | LOCATION_ZIP | |
|---|---|---|---|---|---|
| int | varchar | varchar | varchar | varchar | int |
095 |
barronr@email.com |
1551 Main Street |
Pittsburgh |
PA |
15237 |
237 |
rothm@email.com |
422 First Street |
Richmond |
VA |
23235 |
A SQL command would take the following form:
INSERT INTO AGENTS2 (AGENTID,EMAIL,LOCATION_STREET,LOCATION_CITY,LOCATION_STATE,LOCATION_ZIP)
VALUES (839,'gonzalesn@email.com','9 Fifth Street', 'Morrisville', 'NC', 27566)