cassandra-cliのコマンドたち
cassandra-cliに用意されているコマンドを試す.結果が明らかなものは一部省略.
状態確認
いま動いてる状態を教えてくれるコマンドたち.
# サーバに接続 connect localhost/9160 =>Connected to: "Test Cluster" on localhost/9160 # クラスタ名 show cluster name =>Test Cluster # キースペース名 show keyspaces =>Keyspace1 system MyKeyspace # キースペースの詳細 describe keyspace MyKeyspace =>MyKeyspace.Scores Column Family Type: Super Columns Sorted By: org.apache.cassandra.db.marshal.UTF8Type@1a6a1a7 Column Family Type: Super Column Sorted By: org.apache.cassandra.db.marshal.UTF8Type flush period: null minutes ------
読み書き
読み書きする際は,キースペース.カラムファミリ[キー][スーパーカラム][カラム]と指定する.
# 書き込み set MyKeyspace.Scores['Dan']['grade']['null'] = '1' set MyKeyspace.Scores['Dan']['cource']['math'] = '87' set MyKeyspace.Scores['Dan']['cource']['art'] = '97' set MyKeyspace.Scores['Dana']['grade']['null'] = '2' set MyKeyspace.Scores['Dana']['cource']['math'] = '100' set MyKeyspace.Scores['Dana']['cource']['art'] = '80' # 読み出し get MyKeyspace.Scores['Dan'] => (super_column=grade, (column=null, value=1, timestamp=1274705491363000)) => (super_column=cource, (column=art, value=97, timestamp=1274705498766000) (column=math, value=87, timestamp=1274705495206000)) Returned 2 results. get MyKeyspace.Scores['Dan']['grade'] => (column=null, value=1, timestamp=1274705491363000) Returned 1 results. get MyKeyspace.Scores['Dan']['cource']['math'] => (column=math, value=87, timestamp=1274705495206000) Returned 1 results. # 条件に該当する行をカウント count MyKeyspace.Scores['Dan'] =>2 columns count MyKeyspace.Scores['Dan']['cource'] =>2 columns # 既存のキーにsetすると上書きされる get MyKeyspace.Scores['Dan']['cource']['art'] => (column=art, value=97, timestamp=1274705498766000) set MyKeyspace.Scores['Dan']['cource']['art'] = '96' get MyKeyspace.Scores['Dan']['cource']['art'] => (column=art, value=96, timestamp=1274705547782000) # 削除! del MyKeyspace.Scores['Dan']
気をつけたいところ
全部指定しないとおこられる
set MyKeyspace.Scores['Dan']['grade'] = '1' supercolumn parameter is not optional for super CF Scores
カラムを空にしてもおこられる
set MyKeyspace.Scores['Dan']['grade'][''] = '1' column name must not be empty
存在しないカラムを指定すると落ちる!
# マジで. count MyKeyspace.Scores['Dan']['cource']['math'] =>Exception in thread "main" java.lang.AssertionError at org.apache.cassandra.cli.CliClient.executeCount(CliClient.java:184) at org.apache.cassandra.cli.CliClient.executeCLIStmt(CliClient.java:86) at org.apache.cassandra.cli.CliMain.processCLIStmt(CliMain.java:213) at org.apache.cassandra.cli.CliMain.main(CliMain.java:270)