Database / Apache Cassandra Intermediate and Advanced interview questions
What are User Defined Types (UDTs) in Cassandra?
User Defined Types let you group related fields into a single named, reusable structure, similar to a struct, instead of flattening everything into individual table columns.
CREATE TYPE address ( street text, city text, zip text ); CREATE TABLE customers ( customer_id uuid PRIMARY KEY, name text, home_address frozen<address> ); INSERT INTO customers (customer_id, name, home_address) VALUES (uuid(), 'Jane Doe', {street: '1 Main St', city: 'Austin', zip: '73301'});
- UDTs can be nested inside collections, such as a
list<frozen<address>>for multiple addresses. - When used inside a collection, a UDT (and the collection itself) traditionally had to be marked
frozen, meaning the whole value is serialized as one blob and must be replaced entirely, not partially updated. Newer Cassandra versions allow non-frozen UDTs at the top level of a column, permitting field-level updates. - UDTs improve readability and reduce column sprawl, but frozen UDTs can't have individual fields updated with a lightweight
UPDATE ... SET field = value— you must rewrite the entire value.
UDTs are best used for genuinely structured, cohesive data (like an address or a money amount with currency) rather than as a general substitute for proper table design.
More Related questions...