riakはKVS
riak TSは時系列DBということで大分扱いが違うそうで、Mac OS Xで開発用に扱えるようにしてみる
インストール
- 公式サイトからtarをダウンロードして解凍
% tar zxvf tar zxvf riak-ts-1.5.2-OSX-x86_64.tar
- binにあるriakを実行する
% cd riak-ts-1.5.2
% bin/riak start
- 動作確認
% bin/riak ping
pong
テーブルを作成する
- riakはKVS
- riakの場合はバケットを作成してバケットにkeyとvalueを指定してstoreって感じ
- riak TSはDBっぽい
- riak-shell っていう対話式のshellが用意されている
- riak-shellを使ってDB操作
% bin/riak-shell
>help;
The following functions are available
Extension 'connection':
connect, connection_prompt, ping, reconnect, show_connection, show_cookie
show_nodes
Extension 'debug':
load, observer
Extension 'history':
clear_history, h, history, show_history
Extension 'log':
date_log, log, logfile, regression_log, replay_log, show_log_status
Extension 'shell':
about, q, quit, show_config, show_version
You can get more help by calling help with the
extension name and function name like 'help shell quit;'
For SQL help type 'help SQL'
- 操作はよくある対話式のDBと同じっぽい
- とりあえず helpって打っておけば色々出る
riak-shell(6)>help SQL;
The following SQL help commands are supported:
CREATE - using CREATE TABLE statements
DELETE - deleting data with DELETE FROM
DESCRIBE - examining table structures
EXPLAIN - understanding SELECT query execution paths
INSERT - inserting data with INSERT INTO statements
SELECT - querying data
SHOW - listing tables or showing table creation SQL
SELECT can be used with ORDER BY, GROUP BY and LIMIT clauses. It supports arithmetic on column values and has a variety of aggregation functions: COUNT, SUM, MEAN, AVG, MAX, MIN, STDDEV, STDDEV_SAMP and STDDEV_POP
To get more help type 'help SQL SELECT' (replacing SELECT with another statement as appropriate)
- 大文字小文字の区別はない
- SQLを発行して操作する
riak-shell(2)>show tables;
riak-shell(3)>CREATE TABLE GeoCheckin (id SINT64 NOT NULL, region VARCHAR NOT NULL, state VARCHAR NOT NULL, time TIMESTAMP NOT NULL, weather VARCHAR NOT NULL, temperature DOUBLE, PRIMARY KEY ((id, QUANTUM(time, 15, 'm')), id, time));
Table GeoCheckin successfully created and activated.
riak-shell(4)>show tables;
+----------+------+
| Table |Status|
+----------+------+
|GeoCheckin|Active|
+----------+------+
riak-shell(5)>help sql;
The following SQL help commands are supported:
CREATE - using CREATE TABLE statements
DELETE - deleting data with DELETE FROM
DESCRIBE - examining table structures
EXPLAIN - understanding SELECT query execution paths
INSERT - inserting data with INSERT INTO statements
SELECT - querying data
SHOW - listing tables or showing table creation SQL
SELECT can be used with ORDER BY, GROUP BY and LIMIT clauses. It supports arithmetic on column values and has a variety of aggregation functions: COUNT, SUM, MEAN, AVG, MAX, MIN, STDDEV, STDDEV_SAMP and STDDEV_POP
To get more help type 'help SQL SELECT' (replacing SELECT with another statement as appropriate)
riak-shell(6)>DESCRIBE GeoCheckin;
+-----------+---------+--------+-------------+---------+--------+----+----------+
| Column | Type |Nullable|Partition Key|Local Key|Interval|Unit|Sort Order|
+-----------+---------+--------+-------------+---------+--------+----+----------+
| id | sint64 | false | 1 | 1 | | | |
| region | varchar | false | | | | | |
| state | varchar | false | | | | | |
| time |timestamp| false | 2 | 2 | 15 | m | |
| weather | varchar | false | | | | | |
|temperature| double | true | | | | | |
+-----------+---------+--------+-------------+---------+--------+----+----------+
riak-adminでも作成することが可能
DROP TABLEは今の所できなさそうなので、dataディレクトリを削除してriakを再起動する