LoginSignup
5
6

More than 5 years have passed since last update.

Dockerを利用してOrientDBのグラフデータベースを体験してみよう!

Last updated at Posted at 2016-04-05

グラフ系のデータベース操作をしてみたい、と思い、Neo4J以外にもなにかあるかなー、と探したところOrientDBにたどり着きました。

どんなものなのかを触ってみたかったので下記のリポジトリを利用しました。

1. Dockerを利用してコンテナを起動する

起動時に、ポートとパスワードを指定します。

docker run -d --name orientdb -p 2424:2424 -p 2480:2480  -e ORIENTDB_ROOT_PASSWORD=mysecurepassword joaodubas/orientdb:latest

2. console.shを利用してOrientDBに接続する

ホスト側に、OrientDBのインストーラに含まれるconsole.shを配置します。

そして、以下のようにコマンドを発行することでDockerコンテナのOrientDBに接続することができます。

cd $ORIENTDB_HOME/bin

./console.sh
 ./console.sh 

OrientDB console v.2.1.15 (build 2.1.x@r243c566d47d8877ea0075b8f61abc8880f810a42; 2016-04-04 12:07:47+0000) www.orientdb.com
Type 'help' to display all the supported commands.
Installing extensions for GREMLIN language v.2.6.0

orientdb> connect localhost root mysecurepassword

Connecting to remote Server instance [localhost] with user 'root'...OK

3. データベースを選択する

デフォルトで利用できるデータベースを選択します。

orientdb {server=remote:localhost/}> connect remote:localhost/GratefulDeadConcerts admin admin

Disconnecting from remote server [remote:localhost/]...
OK
Connecting to database [remote:localhost/GratefulDeadConcerts] with user 'admin'...OK

4. レコードを登録する

以下のページを写経してレコード登録しました。

orientdb {db=GratefulDeadConcerts}>  create property Person.lastName string;

Property created successfully with id=1

orientdb {db=GratefulDeadConcerts}>  create property Person.firstName string;

Property created successfully with id=2

orientdb {db=GratefulDeadConcerts}> 

orientdb {db=GratefulDeadConcerts}> 

orientdb {db=GratefulDeadConcerts}>  create class Employee extends Person;

Class created successfully. Total classes in database now: 17

orientdb {db=GratefulDeadConcerts}> create property Employee.empno integer;

Property created successfully with id=3

orientdb {db=GratefulDeadConcerts}>  create property Employee.sal integer;

Property created successfully with id=4

orientdb {db=GratefulDeadConcerts}>  create class Department extends V;

Class created successfully. Total classes in database now: 18

orientdb {db=GratefulDeadConcerts}>  create property Department.deptno integer;

Property created successfully with id=1

orientdb {db=GratefulDeadConcerts}> create property Department.name string;

Property created successfully with id=2

orientdb {db=GratefulDeadConcerts}> create class WorksAt extends E;

Class created successfully. Total classes in database now: 19

orientdb {db=GratefulDeadConcerts}>  create vertex Employee set empno=101,firstName=John,lastName=Jacob,sal=5000;

Error: com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException: Exception during response processing.

Error: com.orientechnologies.orient.core.sql.parser.TokenMgrError: Lexical error at line 1, column 48.  Encountered: "\u2019" (8217), after : ""

orientdb {db=GratefulDeadConcerts}>  create vertex Employee set empno=101,firstName='John',lastName='Jacob',sal=5000; 

Created vertex 'Employee#17:0{empno:101,firstName:John,lastName:Jacob,sal:5000} v1' in 0.020000 sec(s).

orientdb {db=GratefulDeadConcerts}>  create vertex Employee set empno=102,firstName='Adam',lastName='Bill',sal=7000;

Created vertex 'Employee#17:1{empno:102,firstName:Adam,lastName:Bill,sal:7000} v1' in 0.004000 sec(s).

orientdb {db=GratefulDeadConcerts}>  create vertex Employee set empno=103,firstName='David',lastName='Manon',sal=4000;

Created vertex 'Employee#17:2{empno:103,firstName:David,lastName:Manon,sal:4000} v1' in 0.005000 sec(s).

orientdb {db=GratefulDeadConcerts}>  create vertex Department set deptno=10,name='Accounts';

Created vertex 'Department#18:0{deptno:10,name:Accounts} v1' in 0.005000 sec(s).

orientdb {db=GratefulDeadConcerts}>  create vertex Department set deptno=20,name='HR';

Created vertex 'Department#18:1{deptno:20,name:HR} v1' in 0.002000 sec(s).

orientdb {db=GratefulDeadConcerts}> create vertex Department set deptno=20,name='IT';

Created vertex 'Department#18:2{deptno:20,name:IT} v1' in 0.005000 sec(s).

orientdb {db=GratefulDeadConcerts}> create Edge WorksAt from #17:0 to #18:1;

Created edge '[WorksAt#19:0{out:#17:0,in:#18:1} v1]' in 0.023000 sec(s).

orientdb {db=GratefulDeadConcerts}> create Edge WorksAt from #17:1 to #18:0;

Created edge '[WorksAt#19:1{out:#17:1,in:#18:0} v1]' in 0.008000 sec(s).

orientdb {db=GratefulDeadConcerts}> create Edge WorksAt from #17:2 to #18:2; 

Created edge '[WorksAt#19:2{out:#17:2,in:#18:2} v1]' in 0.008000 sec(s).

5. ブラウザでノード同士のコネクションを確認する

にアクセスをして、タブの[Graph]を選択します。

Queryを編集できるテキストボックスがあるので、

select * from Employee

と入力して[Run]を押下。
上記のクエリを削除して、

select * from Department

とすることで以下のような画像が出力されることを確認できました。

Screenshot from 2016-04-05 12-24-49.png

感想

  • Verticaを拡張したエンティティにノードを定義して、コネクタはEdgeとして2ノード以上を指定する、という感じでしょうか。
  • Elixirのライブラリもあるので利用してみたいです。
  • モノ同士のつながりを可視化したい、とか、クラスタリングをしてさらに依存や相関の色付けをしたい、という場合には面白いツールになるかも
  • この画像自体のpngやsvgへのエクスポートはできないのかしら

本日は以上となります。

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6