简体   繁体   中英

Cassandra frozen keyword meaning

What's the meaning of the frozen keyword in Cassandra?

I'm trying to read this documentation page: Using a user-defined type , but their explanation for the frozen keyword (which they use in their examples) is not clear enough for me:

To support future capabilities, a column definition of a user-defined or tuple type requires the frozen keyword. Cassandra serializes a frozen value having multiple components into a single value. For examples and usage information, see "Using a user-defined type", "Tuple type", and Collection type.

I haven't found any other definition or a clear explanation for that in the net.

In Cassandra if you define UDT or Collection as frozen, you can't update UDT's or collection's individual item, you have to reinsert with full value.

A 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.

Source : https://docs.datastax.com/en/cql/3.1/cql/cql_reference/collection_type_r.html

@Alon : "Long story short: frozen = immutable"

For a user-defined type, I have noticed that you can update frozen the set by adding or removing the set elements. For example, let's say we create a table as follows.

create type rule_option_udt(display text, code text);
create TABLE rules (key text, options set<frozen<rule_option_udt>>, primary key (key));

As per the definition we expect that we won't be able to use + or - operation with the options field. But you can use add or remove operation as a normal set.

insert into rules (key, options) values ('fruits', {{display: 'Apple', code: 'apple'}})  ;

update rules set options = options + {{display: 'Orange', code: 'orange'}};

The above update is valid but you can't do the same with simple types such as text. I am not sure if this is expected nature or not but this is how it works for me.

In addition to this <frozen<set<udt>> && set<frozen<udt>> are behaving in the same manner. While describing the table you can see both are being shown as set<frozen<udt>>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM