user3375659
user3375659

Reputation: 65

What is the Difference between tuple and user defined type in Cassandra

Can someone tell me the difference between tuple and user defined types in Cassandra

Upvotes: 2

Views: 2142

Answers (1)

jackiezhu
jackiezhu

Reputation: 422

Datastax documents that

You can use a tuple as an alternative to a user-defined type when you don't need to add new fields.

User-defined types gives you more flexibility with altering the number of fields in case you need to update the data later on, as well as allowing you to give meaningful names to each field. The classic example of how UDTs work is an address.

CREATE TYPE mykeyspace.address (
  street_number int,
  street text,
  city text,
  zip_code int,
  phones set<text>
);

and creating the table

CREATE TABLE users (
  id uuid PRIMARY KEY,
  address frozen <address>
);  

The tuple equivalent would be

CREATE TABLE users (
  id uuid PRIMARY KEY,
  address <tuple<int, text, text, int, set<text>>
);

So tuples would be best for a fixed amount of collected data where field names aren't important (an address column is definitely not a good use case; fields matter--street_number and zip_code could potentially be confused--and you wouldn't be able to add detailed fields later on). UDT would allow this, and also let you query by field name.

Furthermore, there is no significant difference in performance.

Upvotes: 6

Related Questions