# cql 3.0


1. 사용하기 위한 작업

- python 모듈 설치

- sudo easy_install cql

- 실행

- ~/bin/cqlsh host_name host_portnumber

- python ~/bin/cqlsh host_name host_portnumber  

2. cql 사용

- create :  

     CREATE KEYSPACE cql_ks  

      WITH REPLICATION =

  { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };  

 - CREATE TABLE hector_cf_cql (  

  rowkey text PRIMARY KEY,  

  col1 text,  

  col2 text,  

  col3 text,  

  col4 text,  

  col5 set<text>,  

  col6 map<text, text>  

 );  

- insert : 

        INSERT INTO hector_cf_cql  (rowkey, col1, col2, col3) VALUES ('arowkey001', 'val1', 'val2', 'val3');

  INSERT INTO hector_cf_cql  (rowkey, col1, col2, col3, col5)  VALUES ('browkey001', 'val1', 'val2', 'val3', {'string1','string2'});

        INSERT INTO hector_cf_cql  (rowkey, col6) VALUES ('crowkey001',{'map_key1':'map_value1'});

- update   

  UPDATE hector_cf_cql  SET col5 = col5 + {'added_string'} WHERE rowkey = 'browkey001';

  UPDATE hector_cf_cql  SET col5 = {'remove_and_added_string'} WHERE rowkey = 'browkey001';

- delete 

  DELETE col2 FROM hector_cf_cql WHERE rowkey = 'arowkey001';

  DELETE FROM hector_cf_cql WHERE rowkey = 'arowkey001';

    - select  

  select * from hector_cf_cql;

  select col1 from hector_cf_cql;  

        

3. 도입시 주의사항?

- version 별로 지원이 안되거나 기능이 변경되는 부분이 있어 확인이 반드시 필요하다

- 스키마 필요

- 다른 방식(cli 방식)으로 기 생성된 스키마에 대해서는 일부 기능 지원이 제한된다

- select * (o)

- select 특정_column_name_명 (x)

- column 을 추가하기 위해서는 스키마 변경이 선 작업 되어야 한다

'Nosql > cassandra' 카테고리의 다른 글

cassandra java client 소개 및 비교  (0) 2016.08.02
opscenter - cassandra monitor tool  (0) 2016.08.02
cassandra 간단 설치 및 multi cluster 구성하기  (0) 2016.08.02
cassandra-cli  (0) 2016.08.01
cassandra date model  (0) 2016.08.01
Posted by 감각적신사
,

cassandra-cli

Nosql/cassandra 2016. 8. 1. 12:55

# cassandra-cli


1. 실행

- ~/bin/cassandra-cli -h host_name -p host_portnumber

2. cli 사용

- create :

- CREATE KEYSPACE hector_ks  

           with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'  

           and strategy_options = {replication_factor:3};

- CREATE COLUMN FAMILY hector_cf  

             WITH comparator = UTF8Type  

             AND key_validation_class=UTF8Type  

             AND column_metadata = [  

             {column_name: col1, validation_class: UTF8Type, index_type: KEYS}  

             {column_name: col2, validation_class: UTF8Type}  

             {column_name: col3, validation_class: UTF8Type}  

             {column_name: col4, validation_class: UTF8Type}  

             {column_name: col5, validation_class: UTF8Type}  

            ];

- insert :

-  SET hector_cf['rowkey1']['col1']='val1';

-  SET hector_cf['rowkey1'][utf8('extra_col')]=utf8('extra_val');

-  **column_metadata 에 추가하지 않은 값도 insert 가능하다 , 단 타입을 명시해야 한다**

- SET hector_cf['rowkey1'][col3] = 'SAVE20' WITH ttl=864000;

- ttl 단위는 초 이다

- update

- UPDATE COLUMN FAMILY hector_cf WITH comparator = UTF8Type AND column_metadata = [{column_name: col1, index_type: KEYS }];

- set hector_cf['rowkey1']['col1']='val00';

- insert == update 

- delete

- DEL hector_cf ['rowkey1']['col2'];

- DEL hector_cf ['rowkey1'];

- get :

- GET hector_cf[rowkey1][col1];

- GET hector_cf[rowkey1];

- GET hector_cf WHERE col1 = 'val1';

- key 로 선언한 컬럼에 대해 indexing 기능을 지원한다

'Nosql > cassandra' 카테고리의 다른 글

cassandra java client 소개 및 비교  (0) 2016.08.02
opscenter - cassandra monitor tool  (0) 2016.08.02
cassandra 간단 설치 및 multi cluster 구성하기  (0) 2016.08.02
cassandra cql 3.0  (0) 2016.08.01
cassandra date model  (0) 2016.08.01
Posted by 감각적신사
,

1. 데이터 모델

    

    - keyspace : 

- 논리적으로 ColumnFamily를 묶어주는 개념

- 단지 묶어만 줄뿐 데이타 구조나 관계에서는 별다른 영향을 주지 않으나 복제 수를 지정할 수 있다

    - Column Family

- 컬럼들의 집합

- 하나의 row key 에 다수의 column 을 가질 수 있다

- row key 는 기본적으로 timestamp column 을 갖는다

    - Column

    - name : value 로 맵핑된다  



'Nosql > cassandra' 카테고리의 다른 글

cassandra java client 소개 및 비교  (0) 2016.08.02
opscenter - cassandra monitor tool  (0) 2016.08.02
cassandra 간단 설치 및 multi cluster 구성하기  (0) 2016.08.02
cassandra cql 3.0  (0) 2016.08.01
cassandra-cli  (0) 2016.08.01
Posted by 감각적신사
,