Skip to main content

Cassandra: The Definitive Guideの3章と4章を読んだ

Cassandra: The Definitive Guide – 3rd Edition
を読んでるマスタカです

仕事でCassandraをなんとなく使ってたので
ちゃんと勉強しようと思ったわけだ
3章は環境構築
4章はCQLの投げ方


・環境構築
本書だと普通に入れる方法とおまけでDockerって感じだった
Dockerのやり方は以下を参照
https://blog.masterka.net/archives/2591

 

・Dockerでcassandra起動

docker ps -a
docker start CONTAINER_ID

 

・Cluster
cluster_nameの初期値はTest Clusterらしい
https://www.intra-mart.jp/document/library/iap/public/imbox/cassandra_administrator_guide/texts/reference/index.html

 

・Primary key
これにデータが紐づいてる

 

・Partition key
データをまとめたもの

 

・Select
SelectはPKかpartition keyじゃないとエラーになる

CREATE TABLE user (first_name text, last_name text, title text, PRIMARy KEY(last_name, first_name));
select * from user where first_name='Bill';

以下のエラーがでる

InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"

 

・データの削除

DELETE title FROM user WHERE first_name='Bill' AND last_name='Nguyen';

 

・書き込んだ時刻の確認
この時刻を使って同期を取るらしい

SELECT first_name, last_name, title, writetime(title) FROM user ;

 

・TTLの確認

SELECT first_name, last_name, title, TTL(title) FROM user

 

・型
MySQLだと扱いにくいsetやlistやmapも型として使える
さらにユーザ独自の型の定義もできる。
ユーザ独自の型でlistを使う場合はfrozenする。serializeされるらしい

 

こうしてCassandraを何もわからんけど、とりあえず動かせるようになりましたとさ
まだまだ続くよ

関連記事:

Pocket