http://cassandra.apache.org/doc/cql3/CQL.html#types



typeconstants supporteddescription
asciistringsASCII character string
bigintintegers64-bit signed long
blobblobsArbitrary bytes (no validation)
booleanbooleanstrue or false
counterintegersCounter column (64-bit signed value). See Counters for details
decimalintegers, floatsVariable-precision decimal
doubleintegers64-bit IEEE-754 floating point
floatintegers, floats32-bit IEEE-754 floating point
inetstringsAn IP address. It can be either 4 bytes long (IPv4) or 16 bytes long (IPv6). There is no inet constant, IP address should be inputed as strings
intintegers32-bit signed int
textstringsUTF8 encoded string
timestampintegers, stringsA timestamp. Strings constant are allow to input timestamps as dates, see Working with dates below for more information.
timeuuiduuidsType 1 UUID. This is generally used as a “conflict-free” timestamp. Also see the functions on Timeuuid
uuiduuidsType 1 or type 4 UUID
varcharstringsUTF8 encoded string
varintintegersArbitrary-precision integer



* text와 varchar는 같다. aliasing 차이. 




그리고, list, set, map을 기본적으로 지원한다. 

<collection-type> ::= list '<' <native-type> '>'
                    | set  '<' <native-type> '>'
                    | map  '<' <native-type> ',' <native-type> '>'

map 테스트

* 특이사항 : 없는 요소를 update하면 insert가 된다. 



cqlsh:userkeyspace> CREATE TABLE users (

                ...     id text PRIMARY KEY,

                ...     given text,

                ...     surname text,

                ...     favs map<text, text>   // A map of text keys, and text values

                ... );

cqlsh:userkeyspace> INSERT INTO users (id, given, surname, favs)

                ...            VALUES ('jsmith', 'John', 'Smith', { 'fruit' : 'apple', 'band' : 'Beatles' })

                ... ;

cqlsh:userkeyspace> select * from users;


 id     | favs                                  | given | surname

--------+---------------------------------------+-------+---------

 jsmith | {'band': 'Beatles', 'fruit': 'apple'}John |   Smith


(1 rows)


cqlsh:userkeyspace> UPDATE users SET favs['author'] = 'Ed Poe' WHERE id = 'jsmith'

                ... ;

cqlsh:userkeyspace> select * from users;


 id     | favs                                                      | given | surname

--------+-----------------------------------------------------------+-------+---------

 jsmith | {'author': 'Ed Poe', 'band': 'Beatles', 'fruit': 'apple'}John |   Smith


(1 rows)


cqlsh:userkeyspace> UPDATE users SET favs = favs +  { 'movie' : 'Cassablanca' } WHERE id = 'jsmith'

                ... ;

cqlsh:userkeyspace> select * from users;


 id     | favs                                                                              | given | surname

--------+-----------------------------------------------------------------------------------+-------+---------

 jsmith | {'author': 'Ed Poe', 'band': 'Beatles', 'fruit': 'apple', 'movie': 'Cassablanca'}John |   Smith


(1 rows)


cqlsh:userkeyspace> UPDATE users USING TTL 10 SET favs['color'] = 'green' WHERE id = 'jsmith'

                ... ;

cqlsh:userkeyspace> select * from users;


 id     | favs                                                                                                | given | surname

--------+-----------------------------------------------------------------------------------------------------+-------+---------

 jsmith | {'author': 'Ed Poe', 'band': 'Beatles', 'color': 'green', 'fruit': 'apple', 'movie': 'Cassablanca'}John |   Smith


(1 rows)


cqlsh:userkeyspace> select * from users;


 id     | favs                                                                              | given | surname

--------+-----------------------------------------------------------------------------------+-------+---------

 jsmith | {'author': 'Ed Poe', 'band': 'Beatles', 'fruit': 'apple', 'movie': 'Cassablanca'}John |   Smith


(1 rows)


cqlsh:userkeyspace> DELETE favs['author'] FROM users WHERE id = 'jsmith';

cqlsh:userkeyspace> select * from users;


 id     | favs                                                          | given | surname

--------+---------------------------------------------------------------+-------+---------

 jsmith | {'band': 'Beatles', 'fruit': 'apple', 'movie': 'Cassablanca'}John |   Smith


(1 rows)




set 지원

* 특이사항 delete query는 사용하지 않는다. update만 사용.


cqlsh:userkeyspace> CREATE TABLE images (

                ...     name text PRIMARY KEY,

                ...     owner text,

                ...     date timestamp,

                ...     tags set<text>

                ... );

cqlsh:userkeyspace> INSERT INTO images (name, owner, date, tags)

                ...             VALUES ('cat.jpg', 'jsmith', 'now', { 'kitten', 'cat', 'pet' });

cqlsh:userkeyspace> select * from images;


 name    | date                     | owner  | tags

---------+--------------------------+--------+--------------------------

 cat.jpg | 2013-11-13 15:50:17+0900 | jsmith | {'cat', 'kitten', 'pet'}


(1 rows)


cqlsh:userkeyspace> UPDATE images SET tags = tags + { 'cute', 'cuddly' } WHERE name = 'cat.jpg';

cqlsh:userkeyspace> select * from images;


 name    | date                     | owner  | tags

---------+--------------------------+--------+--------------------------------------------

 cat.jpg | 2013-11-13 15:50:17+0900 | jsmith | {'cat', 'cuddly', 'cute', 'kitten', 'pet'}


(1 rows)


cqlsh:userkeyspace> UPDATE images SET tags = tags - { 'lame' } WHERE name = 'cat.jpg';

cqlsh:userkeyspace> select * from images;


 name    | date                     | owner  | tags

---------+--------------------------+--------+--------------------------------------------

 cat.jpg | 2013-11-13 15:50:17+0900 | jsmith | {'cat', 'cuddly', 'cute', 'kitten', 'pet'}


(1 rows)




list에서 삭제할때 update문이 아닌 delete문을 사용하면 hang이 되므로 유의해야 한다.


cqlsh:userkeyspace> delete tags['cuddly'] from images where id = 'cat.jpg';

(hang)



위의 부분은 아파치 지라에 신고했고, 2.0.3 부터는 문제가 없을 예정이다. 

https://issues.apache.org/jira/browse/CASSANDRA-6341




list 이용

* 주의 사항 

It should be noted that append and prepend are not idempotent operations. This means that if during an append or a prepend the operation timeout, it is not always safe to retry the operation (as this could result in the record appended or prepended twice).

Lists also provides the following operation: setting an element by its position in the list, removing an element by its position in the list and remove all the occurrence of a given value in the list. However, and contrarily to all the other collection operations, these three operations induce an internal read before the update, and will thus typically have slower performance characteristics.



cqlsh:userkeyspace> CREATE TABLE plays (

                ...     id text PRIMARY KEY,

                ...     game text,

                ...     players int,

                ...     scores list<int>

                ... )

                ... ;

cqlsh:userkeyspace> UPDATE plays SET players = 5, scores = scores + [ 14, 21 ] WHERE id = '123-afde';

cqlsh:userkeyspace> select * from plays;


 id       | game | players | scores

----------+------+---------+----------

 123-afde | null |       5 | [14, 21]


(1 rows)


cqlsh:userkeyspace> UPDATE plays SET players = 5, scores = [ 12 ] + scores WHERE id = '123-afde';

cqlsh:userkeyspace> select * from plays;


 id       | game | players | scores

----------+------+---------+--------------

 123-afde | null |       5 | [12, 14, 21]


(1 rows)


cqlsh:userkeyspace> UPDATE plays SET scores[1] = 7 WHERE id = '123-afde'; 

cqlsh:userkeyspace> select * from plays;


 id       | game | players | scores

----------+------+---------+-------------

 123-afde | null |       5 | [12, 7, 21]


(1 rows)


cqlsh:userkeyspace> DELETE scores[1] FROM plays WHERE id = '123-afde';  

cqlsh:userkeyspace> select * from plays;


 id       | game | players | scores

----------+------+---------+----------

 123-afde | null |       5 | [12, 21]


(1 rows)


cqlsh:userkeyspace> UPDATE plays SET scores = scores - [ 12, 21 ] WHERE id = '123-afde';

cqlsh:userkeyspace> select * from plays;


 id       | game | players | scores

----------+------+---------+--------

 123-afde | null |       5 |   null


(1 rows)



Posted by '김용환'
,