Cassandra CQL:更改用户定义类型内的特定数据

Cassandra CQL:更改用户定义类型内的特定数据,cassandra,cql,user-defined-types,Cassandra,Cql,User Defined Types,我是CQL的新手;我一直在试验UDT,遇到了这个问题: 一旦我创建了一个用户定义的类型并向表中添加了新行,是否有任何方法可以在不必重新定义所有字段的情况下更新其中的字段?例如,我有一个名为test的表,由名称文本、主键和以下格式的用户定义类型组成: create type favorites( color text, number int, food text, location set<text> ); 现在,我想把海绵宝宝最喜欢的颜色改为“粉色”,并将“手套世界”添加到他最喜欢

我是CQL的新手;我一直在试验UDT,遇到了这个问题:

一旦我创建了一个用户定义的类型并向表中添加了新行,是否有任何方法可以在不必重新定义所有字段的情况下更新其中的字段?例如,我有一个名为test的表,由名称文本、主键和以下格式的用户定义类型组成:

create type favorites(
color text,
number int,
food text,
location set<text>
);
现在,我想把海绵宝宝最喜欢的颜色改为“粉色”,并将“手套世界”添加到他最喜欢的位置列表中。我现在知道如何做到这一点的唯一方法就是重新定义一切:

update test 
set favorite_stuff = {
color:'pink',
number:12,
food:'krabby patty',
location:{'bikini bottom', 'goo lagoon', 'glove world'}
} where name='Spongebob';

有更好的方法吗?

我假设您的表模式为CREATE table testname text主键,favorite_stuff freezed;。收藏夹内容必须冻结,因为cassandra不支持带有嵌套非冻结集合的非冻结UDT。使用此架构,由于以下原因,您无法进行任何部分更新

冻结值将多个组件序列化为单个值。非冻结类型允许对单个字段进行更新。Cassandra将冻结类型的值视为blob。必须覆盖整个值

但是,您可以按照下面的说明更改收藏夹类型架构。然后,您将能够更新单个atribute,但不能更新位置属性,因为现在位置已冻结

create type favorites(
    color text,
    number int,
    food text,
    location frozen<set<text>>
);


cqlsh:test> update test set favorite_stuff.color='pink' where name='Spongebob';
cqlsh:test> select * from test;

 name      | favorite_stuff
-----------+----------------------------------------------------------------------------------------------
 Spongebob | {color: 'pink', number: 12, food: 'krabby patty', location: {'bikini bottom', 'goo lagoon'}}

(1 rows)
cqlsh:test>
create type favorites(
    color text,
    number int,
    food text,
    location frozen<set<text>>
);


cqlsh:test> update test set favorite_stuff.color='pink' where name='Spongebob';
cqlsh:test> select * from test;

 name      | favorite_stuff
-----------+----------------------------------------------------------------------------------------------
 Spongebob | {color: 'pink', number: 12, food: 'krabby patty', location: {'bikini bottom', 'goo lagoon'}}

(1 rows)
cqlsh:test>