Cassandra frozen 关键字含义

Cassandra frozen keyword meaning

Cassandra 中 frozen 关键字的含义是什么?

我正在尝试阅读此文档页面:Using a user-defined type,但他们对 frozen 关键字(他们在示例中使用的关键字)的解释对我来说不够清楚:

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.

我还没有在网上找到任何其他定义或明确的解释。

在 Cassandra 中,如果您将 UDT 或集合定义为冻结的,则无法更新 UDT 或集合的单个项目,您必须重新插入完整值。

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.

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

@阿隆:"Long story short: frozen = immutable"

对于用户定义的类型,我注意到您可以通过添加或删除集合元素来更新冻结集合。例如,假设我们创建一个 table 如下。

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

根据定义,我们预计我们将无法对选项字段使用 + 或 - 操作。但您可以像普通集合一样使用添加或删除操作。

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

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

以上更新有效,但您不能对文本等简单类型执行相同的操作。我不确定这是否是预期的性质,但这对我来说是这样的。

除此之外 <frozen<set<udt>> && set<frozen<udt>> 的行为方式相同。在描述 table 时,您可以看到两者都显示为 set<frozen<udt>>