Update a collection type of a custom type in cassandra

二次信任 提交于 2019-12-10 11:52:26

问题


How can I append a new element to a set which is in a custom type in Cassandra.

custom_type is :

CREATE TYPE custom_type (
   normal_type    TEXT,
   set_type Set<TEXT>
);

and the table to be updated is :

CREATE TABLE test_table (
   id          TEXT,
   my_type      FROZEN<custom_type>,
   clustering_key TEXT,
   PRIMARY KEY ((id),clustering_key)
);

Tried below query but did not work.

@Query("update test_table set  my_type.set_type = my_type.set_type + {'newelement'} where id=?1 and clustering_key=?2")

Any Idea on how to do that? Using [cqlsh 5.0.1 | Cassandra 3.11.1 | CQL spec 3.4.4


回答1:


When you say frozen, then the whole value is treated as one piece (blob), so you can't update parts of this field. Official documentation states:

When using the frozen keyword, you cannot update parts of a user-defined type value. The entire value must be overwritten. Cassandra treats the value of a frozen, user-defined type like a blob.



来源:https://stackoverflow.com/questions/48662850/update-a-collection-type-of-a-custom-type-in-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!