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?
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.
Duration columns cannot be used in a table's PRIMARY KEY . This limitation is due to the fact that durations cannot be ordered.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With