22
OrientDB graph database in practice Aurelijus Banelis

OrientDB: graph database in practice - · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

  • Upload
    hathuan

  • View
    224

  • Download
    4

Embed Size (px)

Citation preview

Page 1: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

OrientDBgraph database

in practice

Aurelijus Banelis

Page 2: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

About me

Aurelijus Banelis

[email protected]

Software Engineer at NFQ

2About

Page 3: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

You will learn

3In short

WHATGraph

Graph database

WHYReal worldexample

HOWWith PHP

With relational databaseBest practice

Page 4: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

WHAT: Graph

4What

Source: http://commons.wikimedia.org/wiki/File:Tiskevicius_Juozapas_1835-1891.JPG

Not Graf mathematical graphRead more at: http://en.wikipedia.org/wiki/Graph_%28mathematics%29

Page 7: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

Graph database is optimized for many relations

7WhatRead more at:http://www.orientechnologies.com/docs/last/orientdb.wiki/Tutorial-Relationships.html

http://youtu.be/U0dB7DRXv-I?list=PLxBRkBr-uobtojUxJarvGddSgGJ6KkI85

Page 8: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

Summary (1/3)

8

WHATGraph

Graph database

WHYReal worldexample

HOWWith PHP

With relational databaseBest practice

GraphVertices and edgesAs data visualization

Graph databaseOptimized for many relations

What

Page 11: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

WHAT:

11WHY

License: Apache 2 (free + for commercial)

Structures: Schema-hybrid, with extend

Scalability: Sharding, replication, WAL

Used by: Cisco, Ericsson

API: JavaLib, binary, REST

Query languages:WEB, SQL, Gremlin

Storage:File, memory, remote

Documentation:Tutorials, groups, source

Transactions:ACID, MVCC

Attributes:Read-only, metadata

Results:Synchronous, asynchronous

Text search:Lucene full text index

Page 12: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

12WHY

Time for

DEMO

Page 13: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

Summary (2/3)

13

WHATGraph

Graph database

WHYReal worldexample

HOWWith PHP

With relational databaseBest practice

Structures/OperationsTrees with cycles = graphTraverse like operations

ToolsDebugging complex structures

Business logicList or association based

WHY

Page 14: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

HOW: Notes for developers

14

PHPOrientDB in PHP world

How

Migrationand learning cost

Relationaldatabase integration

Designstructures in database

Page 15: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

HOW: in PHP world

15How

PhpOrient "require": { "ostico/phporient": "1.1.*" }

Official PHP >=5.4 OrientDB >=1.7.4

OrientDB-PHP "require": { "orientdb-php/orientdb-php": "dev-master" }

First/oldPHP >=5.3 API getting outdated

OrientDB ODM "require": { "sgpatil/orientdb-odm": "dev-master" } "require": { "concept-it/orient-db-bundle": "dev-master" }

DoctrineSymfonyPHP >=5.3 On top of OrientDB-PHP

REST/HTTP API http://0.0.0.0:2480Slower

OrientDB-PHP

Not recommendNo complex results = no graph

Use PhpOrient instead

Page 16: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

HOW: PhpOrient

16How

/** @var Record[] $results */$results = $client->query(  'SELECT FROM Testas WHERE c.d.e = 132');foreach ($results as $res) {  print "{$res->getRid()} {$res['c']['d']['f']}";}

/** @var Bag $inParent */ /** @var ID $id */$inParent = $res['in_Parent'];foreach ($inParent as $id) {   $child = $client->recordLoad($id);}

Page 17: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

HOW: Migration costs

17How

* Based on time used in my personal project

Other tasksOrientDBLearningCodingDebugging

Page 18: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

HOW: Integrate with relational database

18How

OrientDB ETLNative tool to importToo hard for n-n relations

SQL Batch Execute multiple queries at the server side

LET v1 = CRAETE VERTEX Article SET name="123"LET v2 = CRAETE VERTEX Action SET name="456"LET v3 = CRAETE VERTEX Stock SET house="A", amount=2CREATE EDGE Discount FROM $v1 TO $v2CREATE EDGE Contains FROM $v3 TO $v1

RETURN [$v1, $v2, $v3]

Page 19: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

HOW: Design structure in database

19How

Where to put parameters?

Only in vertices

In edges●Not shown in Graph view●Strange Traverse behavior

●Easier to implement caching●Easier to extend relations●Imitating edge parameter with inheritance of vertices

Page 20: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

Summary (3/3)

20

WHATGraph

Graph database

WHYReal worldexample

HOWWith PHP

With relational databaseBest practice

PHP wrapperPhpOrient

Migration costTime for debugging/tests

Relational databaseUse SQL Batch

Design databaseUse light edges

How

Page 21: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

Questions?

?

WHATGraph

Graph database

WHYReal worldexample

HOWWith PHP

With relational databaseBest practice

Page 22: OrientDB: graph database in practice -   · PDF fileYou will learn In short 3 WHAT Graph Graph database WHY Real world example HOW With PHP With relational database Best practice

References and useful links

22i

●http://www.orientechnologies.com ●https://github.com/orientechnologies/orientdb/wiki/SQL-Functions●https://github.com/orientechnologies/orientdb/wiki/SQL-Traverse●http://www.orientechnologies.com/docs/last/orientdb.wiki/Programming-Language-Bindings.html

●https://github.com/orientechnologies/orientdb/wiki/Document-Database#prepared-query

●https://github.com/orientechnologies/orientdb/wiki/Fetching-Strategies●http://neo4j.com/●http://auginte.com