Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non frozen collections and user defined types on Cassandra 2.1.8

I'm trying to run the following example from here

  CREATE TYPE address (
          street text,
          city text,
          zip int
      );

 CREATE TABLE user_profiles (
      login text PRIMARY KEY,
      first_name text,
      last_name text,
      email text,
      addresses map<text, address>
  );

However, when I try to create the user_profiles table, I get the following error:

InvalidRequest: code=2200 [Invalid query] message="Non-frozen collections are not
allowed inside collections: map<text, address>

Any thoughts on why this could be happening?

like image 222
userNotFound Avatar asked Aug 11 '15 23:08

userNotFound


People also ask

What is frozen collection in Cassandra?

Using frozen in a collectionA frozen value serializes multiple components into a single value. Non-frozen types allow updates to individual fields. Cassandra treats the value of a frozen type as a blob. The entire value must be overwritten.

Which one is not a valid type of primary key in Cassandra?

Duration columns cannot be used in a table's PRIMARY KEY . This limitation is due to the fact that durations cannot be ordered.

What is a type in Cassandra?

Apache Cassandra supports the Cassandra Query Language, or CQL. Apache Cassandra Data Types are the classifications of data that indicate what type of data can be stored in a variable or object.

What is UDT in Cassandra?

User-Defined Types (UDTs) can be used to attach multiple data fields to a column. User-defined types (UDTs) can attach multiple data fields, each named and typed, to a single column. The fields used to create a UDT may be any valid data type, including collections and other existing UDTs.


2 Answers

I am running 2.1.8 and I get the same error message. To fix this, you need the frozen keyword:

 CREATE TABLE user_profiles (
      login text PRIMARY KEY,
      first_name text,
      last_name text,
      email text,
      addresses map<text, frozen <address>>
  );

Frozen is necessary for UDTs (for now) as it serializes them into a single value. A similar, better example for you to follow might be the one in the User Defined Type documentation. Give that a try.

like image 51
Aaron Avatar answered Oct 06 '22 04:10

Aaron


I was getting this message when I mistakenly used "string" instead of "text" in a cassandra map, like:

mymap map<bigint, string> 

I followed this stackoverflow thread from google and I thought this information could save someone a few minutes of their time.

like image 31
Soid Avatar answered Oct 06 '22 02:10

Soid