Arunkumar
Arunkumar

Reputation: 107

How to Create nested collection map<text,list<text>> type in cassandra database 2.2.1

create table tbl_master_values (
  dbid int primary key,
  user_dbid int, reg_dbid int,
  module_dbid int,
  fields_value map<text,list<text>>,
  created_date timestamp,
  modified_date timestamp);

It returns this error:

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

Upvotes: 4

Views: 8948

Answers (2)

Nikunj Pandya
Nikunj Pandya

Reputation: 186

In Cassandra, you can use non-frozen collections if you intend to add or remove entries through in-Cassandra query. But when you intend to use UDT or nested collection inside your map, you must declare former as frozen. For example in your case:

    create table tbl_master_values (
    dbid int primary key,
    user_dbid int, reg_dbid int,
    module_dbid int,
    fields_value map<text,frozen<list<text>>>,
    created_date timestamp,
    modified_date timestamp);

If you are using Map for storing and retrieving information, and not updating the row you can declare it as:

    frozen<map<text, list<text>>>

Remember frozen<> keyword will not let you update that entity and store it as blob type. Read here for clarification on updating:

https://docs.datastax.com/en/cql/3.3/cql/cql_using/useInsertMap.html

Upvotes: 4

Aaron
Aaron

Reputation: 57798

Non-frozen collections are not allowed inside collections: map>

Cassandra is telling you that it cannot complete the operation without using the frozen keyword.

fields_value frozen<map<text, list<text>>>,

Keep in mind that frozen tells Cassandra to treat the value as a blob, and prevents individual parts of the value from being modified. When you make a change to a frozen collection you are serializing and rewriting all of the items stored. So this probably won't be a good solution for a frequently-changing collection.

Upvotes: 3

Related Questions