KVS
nosql
Cassandra
cql
cqlsh

『DataStax DevCenter』というCassandraのCQLツール(GUIツール)のご紹介

『DataStax DevCenter』というCassandraのCQLツール(GUIツール)をご紹介します。
※Oracle でいうところの「SQL Developer」などにあたるツールです。

DevCenter.png

①DataStax Academyのアカウントを作成する。

Create new account | DataStax Academy: Free Cassandra Tutorials and Training
https://academy.datastax.com/user/register?destination=home

②『DataStax DevCenter』をダウンロードする。

https://academy.datastax.com/downloads?destination=downloads/ops-center&dxt=DX#devcenter

DevCenter._DLpng.png

③system keyspace で、システム日付とTimeUUIDを取得してみる。

Query
SELECT dateof(now()) as sysdate, now() as timeuuid FROM system.local;

Result

sysdate timeuuid
2018-02-16 07:30:30+0000 44529f03-12eb-11e8-9fb5-fddf3f702750


以下は、CQLコマンドのサンプルです。

keyspaceの作成

Query

CREATE KEYSPACE [keyspace_name] WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

keyspaceの確認(cqlsh> で実行)

Query
DESCRIBE KEYSPACE [keyspace_name];
DESC KEYSPACE [keyspace_name];

Result

CREATE KEYSPACE keyspace_name WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}  AND durable_writes = true;

keyspaceの削除

Query
DROP KEYSPACE [keyspace_name];

Tableの作成

Query

CREATE TABLE keyspace_name.table_name (
    column_id uuid,
    column_str text,
    column_int int,
    column_data text,
    PRIMARY KEY (column_id, column_str, column_int)
);

Tableの確認(cqlsh> で実行)

Query
DESCRIBE KEYSPACE [keyspace_name];
DESC KEYSPACE [keyspace_name];

Result

CREATE KEYSPACE keyspace_name WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}  AND durable_writes = true;

CREATE TABLE keyspace_name.table_name (
    column_id uuid,
    column_str text,
    column_int int,
    column_data text,
    PRIMARY KEY (column_id, column_str, column_int)
) WITH CLUSTERING ORDER BY (column_str ASC, column_int ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99.0PERCENTILE';

Tableの削除

Query
DROP TABLE keyspace_name.table_name;

INSERT

Query

INSERT INTO keyspace_name.table_name (column_id, column_str, column_int, column_data) 
VALUES (44529f03-12eb-11e8-9fb5-fddf3f702750, 'String', 1, 'Data');

SELECT

Query
SELECT * FROM keyspace_name.table_name WHERE column_id = 44529f03-12eb-11e8-9fb5-fddf3f702750;

Result

column_id column_str column_int column_data
44529f03-12eb-11e8-9fb5-fddf3f702750 String 1 Data

同一KEYのINSERT(UPDATEされる)

Query

INSERT INTO keyspace_name.table_name (column_id, column_str, column_int, column_data) 
VALUES (44529f03-12eb-11e8-9fb5-fddf3f702750, 'String', 1, 'INSERT(UPDATE)');

Result

column_id column_str column_int column_data
44529f03-12eb-11e8-9fb5-fddf3f702750 String 1 INSERT(UPDATE)

UPDATE

Query

UPDATE keyspace_name.table_name SET column_data = 'UPDATE' 
WHERE column_id = 44529f03-12eb-11e8-9fb5-fddf3f702750 AND column_str = 'String' AND column_int = 1;

Result

column_id column_str column_int column_data
44529f03-12eb-11e8-9fb5-fddf3f702750 String 1 UPDATE

DELETE

Query

DELETE FROM keyspace_name.table_name 
WHERE column_id = 44529f03-12eb-11e8-9fb5-fddf3f702750 AND column_str = 'String' AND column_int = 1;

TRUNCATE

Query
TRUNCATE keyspace_name.table_name;

参考リンク

おわりに

Qiitaの [cql][cqlsh] のタグにアイコンが無かったので、Qiitaのアイコンをまねしてデザインしてみた!
なかなか良い出来だ!と思ったら「いいね!」をお願いします!

CQL.png