cassandra 存储list数组
Posted 将者,智、信、仁、勇、严也。
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cassandra 存储list数组相关的知识,希望对你有一定的参考价值。
demo如下:
CREATE TABLE users3 ( user_id text PRIMARY KEY, first_name text, last_name text, emails list<text> ); INSERT INTO users3 (user_id, first_name, last_name, emails) VALUES(‘frodo‘, ‘Frodo‘, ‘Baggins‘, [‘[email protected]‘, ‘[email protected]‘]); UPDATE users3 SET emails = emails + [‘[email protected]‘] WHERE user_id = ‘frodo‘; SELECT user_id, emails FROM users3 WHERE user_id = ‘frodo‘;
Collection type
A collection column is declared using the collection type, followed by another type, such as int
or text
, in angle brackets. For example, you can create a table having a list of textual elements, a list of integers, or a list of some other element types.
list<text>
list<int>
Collection types cannot be nested, but frozen collection types can be nested inside frozen or non-frozen collections. For example, you may define a list within a list, provided the inner list is frozen:
list<frozen <list<int>>>
Indexes may be created on a collection column of any type.
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.
column_name collection_type<data_type, frozen<column_name>>
For example:
CREATE TABLE mykeyspace.users (
id uuid PRIMARY KEY,
name frozen <fullname>,
direct_reports set<frozen <fullname>>, // a collection set
addresses map<text, frozen <address>> // a collection map
score set<frozen <set<int>>> // a set with a nested frozen set
);
list的话针对下面的{}修改为[]即可!
Using the set type
A set stores a group of elements that are returned in sorted order when queried. A column of type set consists of unordered unique values. Using the set data type, you can solve the multiple email problem in an intuitive way that does not require a read before adding a new email address.
Procedure
以上是关于cassandra 存储list数组的主要内容,如果未能解决你的问题,请参考以下文章
Cassandra List<UDT> 未使用 datastax java driver 4.0.0 反序列化
在 Cassandra 中存储地理位置详细信息和在 Elastic Search 中存储索引的最佳方式?
如何从 cassandra 或 hbase 中提取 leveldb 类型的数据存储(sstable + memtable)?