ddbcliをDynamoDB Localに対応させましした

対話型DynamoDBクライアントのddbcliDynamoDB Localに対応させました。(>= 0.2.2)


使い方は以下の通り。

shell> ddbcli --uri localhost:8000
localhost:8000> select all * from foo;

employeesを入れてみる

MySQLEmployees Sample DatabaseからemployeesテーブルのデータをDynamoDB Localに入れてみました。


まずDynamoDB Localを起動。


~/dynamodb_local_2013-09-12$ java -jar DynamoDBLocal.jar
2013-09-14 13:56:52.253:INFO:oejs.Server:jetty-8.y.z-SNAPSHOT
2013-09-14 13:56:52.326:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8000


DynamoDB Localにテーブルを作成。


localhost:8000> create table employees (
-> emp_no number hash,
-> last_name string range,
-> index idx_first_name (first_name string) all
-> ) read=20, write=20;
localhost:8000> show create table employees;
CREATE TABLE `employees` (
`emp_no` NUMBER HASH,
`last_name` STRING RANGE,
INDEX `idx_first_name` (`first_name` STRING) ALL
) read=20, write=20


mysqldumpでエクスポートしたデータをインポート。


~$ mysqldump -u root -h 127.0.0.1 -c -t employees employees | grep -i ^insert | ddbcli --uri localhost:8000
// 17925 rows changed (98.08 sec)

// 17919 rows changed (95.36 sec)

// 17935 rows changed (93.34 sec)

// 17928 rows changed (100.91 sec)

// 17930 rows changed (98.27 sec)

// 17631 rows changed (96.17 sec)

// 17623 rows changed (102.98 sec)

// 17620 rows changed (104.69 sec)

// 17635 rows changed (105.37 sec)

// 17631 rows changed (108.73 sec)

// 17619 rows changed (109.56 sec)

// 17622 rows changed (124.44 sec)

// 17629 rows changed (127.14 sec)

// 17624 rows changed (119.26 sec)

// 17633 rows changed (120.83 sec)

// 17618 rows changed (124.18 sec)

// 16502 rows changed (120.15 sec)


データを確認…


localhost:8000> select all * from employees limit 3;
[
{"birth_date":"1956-05-15","emp_no":209963,"first_name":"Cathie","gender":"M","hire_date":"1997-04-11","last_name":"Keohane"},
{"birth_date":"1957-09-16","emp_no":452020,"first_name":"Aemilian","gender":"M","hire_date":"1990-09-25","last_name":"Roccetti"},
{"birth_date":"1959-07-01","emp_no":475220,"first_name":"Dayanand","gender":"M","hire_date":"1989-09-01","last_name":"Waterhouse"}
]
// 3 rows in set (0.01 sec)
// has more

localhost:8000> select all count(*) from employees;
300024
// 1 row in set (105.95 sec)

localhost:8000> show table status;
{
"employees": {
"TableStatus": "ACTIVE",
"ItemCount": 300024,
"TableSizeBytes": 27023049,
"ReadCapacityUnits": 20,
"WriteCapacityUnits": 20
}
}
// 1 row in set (1.76 sec)

…ちゃんと入っていますね。


プライマリキーで検索。


localhost:8000> select * from employees where emp_no = 16998;
[
{"birth_date":"1963-07-14","emp_no":16998,"first_name":"Katsuyuki","gender":"F","hire_date":"1989-12-28","last_name":"Weedon"}
]
// 1 row in set (0.22 sec)


インデックスで検索。


localhost:8000> select * from employees use index (idx_first_name) where emp_no = 16998 and first_name begins_with 'K';
[
{"birth_date":"1963-07-14","emp_no":16998,"first_name":"Katsuyuki","gender":"F","hire_date":"1989-12-28","last_name":"Weedon"}
]
// 1 row in set (0.36 sec)

localhost:8000> select * from employees use index (idx_first_name) where emp_no = 16998 and first_name begins_with 'X';
[
]
// 0 row in set (0.36 sec)