본문 바로가기

Cassandra

Cassandra - Set, List, Map 사용하기

카산드라는 collection 을 column 값(value)으로 입력 할 수 있다.


collection의 종류 로는 set, list, map 이 있다.


생성과 사용 법은 아래 글을 보자



CREATE TABLE users (

user_id text PRIMARY KEY,

emails set<text>,

groups list<text>,

option map<text, int>

);


INSERT INTO users (user_id, emails, groups, option)

VALUES ('doubleP', {'purepleya@gmail.com'}, ['home', 'company'], {'java' : 3, 'python' : 2});





SET

UPDATE users

SET emails = emails + {'ma-pd@nate.com'}

WHERE user_id = 'doubleP';


UPDATE users

SET emails = emails - {'purepleya@gmail.com'}

WHERE user_id = 'doubleP';


DELETE emails

FROM users

WHERE user_id = 'doubleP';




LIST

UPDATE users

SET groups = groups + ['church']

WHERE user_id = 'doubleP';


UPDATE users

SET groups = ['alone'] + groups

WHERE user_id = 'doubleP';


UPDATE users

SET groups = groups - ['company']

WHERE user_id = 'doubleP';


DELETE groups 

FROM users

WHERE user_id = 'doubleP';




MAP

UPDATE users

SET option['java'] = 2

WHERE user_id = 'doubleP';


DELETE option['java']

FROM users

WHERE user_id = 'doubleP';


UPDATE users

SET option['.net'] = 4

WHERE user_id = 'doubleP';


DELETE option

FROM users

WHERE user_id = 'doubleP';



반응형