Works with persistent graphs using OrientDB

Preview:

DESCRIPTION

This talk will present OrientDB open source project and its capability to handle persistent graphs in different ways. OrientDB presentation Java Graph Native API SQL+graph extensions HTTP API Blueprints API Gremlin usage Console tool Studio web tool

Citation preview

www.orientechnologies.com

Can I have a fastGraphDB

with flexible schema,ACID Transactions,

SQL support, Securityall for FREE??

The database for graphs

+12 yearsof research

www.orientechnologies.com

+2 yearsof design and develop

www.orientechnologies.com

OrientDB=

best features of newest NoSQL solutions+

best features of Relational DBMS+

True Graph enginewww.orientechnologies.com

Relationshipsare direct links

no Relational JOINS to connect multiple tables

Load trees and graphs in few ms!

www.orientechnologies.com

Ø configdownload, unzip, run!

cut & paste the db

www.orientechnologies.com

No dependencieswith 3rd parties software

no conflicts with other software

just 1 Mb of run-time libraries

www.orientechnologies.com

Java®

runs everywhere is available JRE1.5+

robust engine

www.orientechnologies.com

150,000records per second

www.orientechnologies.com

Schema-lessschema is not mandatory, relaxed model,

collect heterogeneous documents all together

www.orientechnologies.com

Schema-fullschema with constraints on fields and validation rules

Customer.age > 17Customer.address not nullCustomer.surname is mandatoryCustomer.email matches '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'

www.orientechnologies.com

Schema-mixedschema with mandatory and optional fields + constraints

the best of schema-less and schema-full modes

www.orientechnologies.com

ACID Transactionsdb.begin();

try{ // your code ... db.commit();

} catch( Exception e ) { db.rollback();}

www.orientechnologies.com

Complex typesnative support for collections, maps (key/value)

and embedded documentsno more additional tables to handle them

www.orientechnologies.com

SQLselect * from employee where name like '%Jay%' and status=0

www.orientechnologies.com

www.orientechnologies.com

Why reinventyet another language when

the 100% of developers alreadyknows SQL?

OrientDB begins from SQLbut improve it with new

operators for graph manipulation

www.orientechnologies.com

For the most of the querieseveryday a programmer needs

SQL is simpler,more readable and

compact thenScripting (Map/Reduce)

www.orientechnologies.com

SELECT SUM(price) as prices, SUM(cost) as costs, prices-costs, margin/price FROM Balance

VSfunction (key, values) { var price = 0.0, cost = 0.0, margin = 0.0, marginPercent = 0.0; for (var i = 0; i < values.length; i++) { price += values[i].price; cost += values[i].cost; } margin = price - cost; marginPercent = margin / price; return { price: price, cost: cost, margin: margin, marginPercent: marginPercent };}

Asynchronous Queryinvoke callback when a record matches the condition

doesn't collect the result setperfect for immediate results

useful to compute aggregates

www.orientechnologies.com

Enhanced SQLSQL is not enough for collections, maps, trees and graphs

need to enhance SQL syntaxEasy syntax derived from JDO/JPA standards

www.orientechnologies.com

SQL & relationshipsselect from Account where address.city.country.name = 'Italy'

select from Account where addresses contains (city.country.name = 'Italy')

www.orientechnologies.com

SQL & stringsselect from Profile where name.toUpperCase() = 'LUCA'

select from City where country.name.substring(1,3).toUpperCase() = 'TAL'

select from Agenda where phones contains ( number.indexOf( '+39' ) > -1 )

select from Agenda where email matches '\bA-Z0-9._%+-?+@A-Z0-9.-?+\.A-Z?{2,4}\b'

www.orientechnologies.com

SQL & schema-lessselect from Profile where any() like '%Jay%'

select from Stock where all() is not null

www.orientechnologies.com

SQL & collectionsselect from Tree where children contains ( married = true )

select from Tree where children containsAll ( married = true )

select from User where roles containsKey 'shutdown'

select from Graph where edges.size() > 0

www.orientechnologies.com

Binary protocolFast compressed JSON over tcp/ip

available for Javaand soon C, C++ and Ruby

www.orientechnologies.com

Language bindingsJava as native

JRuby, Scala and Javascript readyC, C++, Ruby, Node.js in progress

www.orientechnologies.com

Your language isnot supported (yet)?

Write an adapter using theC, Java or HTTP binding

www.orientechnologies.com

HTTP RESTfulfirewall friendly

use it from the web browseruse it from the ESB (SOA)

www.orientechnologies.com

Native JSON{ '@rid' = '26:10', '@class' = 'Developer', 'name' : 'Luca', 'surname' : 'Garulli', 'outEdges' : [ #10:33, #10:232 ]}

www.orientechnologies.com

Import/Exportuses JSON format

online operations (don't stop the database)

www.orientechnologies.com

RB+Tree index

the best of B+Tree and RB-Treefast on browsing, low insertion costIt's a new algorithm (soon public)

www.orientechnologies.com

Hookssimilar to triggers

catch events against records, database and transactions

implement custom cascade deletion algorithmenforce constraints

www.orientechnologies.com

Securityusers and roles, encrypted passwords

fine grain privileges

www.orientechnologies.com

Multi-Master ClusteringHight-Availability

Cluster of distributed server nodesSynchronous, Asynchronous and Read-Only

replicationLoad-balancing between client servers and↔

Servers Servers↔

www.orientechnologies.com

ConsoleORIENT database v.0.9.23 www.orientechnologies.comType 'help' to display all the commands supported.

> connect remote:localhost/demo admin adminConnecting to database [remote:localhost/demo] with user 'admin'...OK

> select from profile where nick.startsWith('L')---+--------+--------------------+--------------------+--------------------+ #| REC ID |NICK |SEX |AGE |---+--------+--------------------+--------------------+--------------------+ 0| 10:0|Lvca |male |34 1| 10:3|Leo |male |22 2| 10:7|Luisa |female |273 item(s) found. Query executed in 0.013 sec(s).

> closeDisconnecting from the database [demo]...OK

> quit

www.orientechnologies.com

OrientDB Studio/SQL query

www.orientechnologies.com

Graph Database modelwrapper on top of Document Database

Few simple concepts: Vertex, Edge,Property and Index

www.orientechnologies.com

www.orientechnologies.com

OGraphVertex

PersonAddress : Address

Inheritance

CustomertotSold : float

ProvidertotBuyed : float

OGraphEdge

Works

since : Date

Residessince : Datetill : Date

Knows

Level : LEVELS

Vehiclebrand : BRANDS

Polymorphic SQL QueryList<ODocument> result = database.query( new OSQLSynchQuery(

"select from Person where city.name = 'Rome'" ));

www.orientechnologies.com

Queries are polymorphicsand subclasses of Person can be

part of result set

www.orientechnologies.com

OGraphDatabaseNative, damn fast, not the most beautiful API

ODatabaseGraphTxNative, Fluent API

3 API

OrientGraphTinkerPop Blueprints, slowest but:

common to other impls, Gremlin, SPARQL (Sail)

All APIsare compatibleamong them!

So use the right onefor the right case

www.orientechnologies.com

OGraphDatabaseNative, damn fast, not the most beautiful API

What to choose?

OGraphDatabase if you needPerformance at any cost.

Use it for massive insertion orlow resources

www.orientechnologies.com

What to choose?

ODatabaseGraphTx if you needgood performance and fluent API

Use it for all day code

ODatabaseGraphTxNative, Fluent API

www.orientechnologies.com

What to choose?

OrientGraph if you want to stayPortable

at the cost of speed (the slowest)

or to use Gremlin language,or as RDF store + SPARQL

OrientGraphTinkerPop Blueprints, slowest but:

common to other impls, Gremlin, SPARQL (Sail)

Fetch plansChoose what to fetch on query and vertexes/edges loading

Vertexes/Edges not fetched will be lazy-loaded on requestOptimizes network latency

www.orientechnologies.com

Fetch plansVertex Luca | | lives city +---------> Vertex ------------> Vertex | 10th street Italy | knows +--------->* [Vertex Vertex Vertex ] [ Marko John Nicholas]

www.orientechnologies.com

Load only the root vertex= *:0

Fetch plansVertex Luca | | lives city +---------> Vertex ------------> Vertex | 10th street Italy | knows +--------->* [Vertex Vertex Vertex ] [ Marko John Nicholas]

www.orientechnologies.com

Load root + address= *:0 lives.city:0

Fetch plansVertex Luca | | lives city +---------> Vertex ------------> Vertex | 10th street Italy | knows +--------->* [Vertex Vertex Vertex ] [ Marko John Nicholas]

www.orientechnologies.com

Load root + all known= *:0 knows:1

Fetch plansVertex Luca | | lives city +---------> Vertex ------------> Vertex | 10th street Italy | knows +--------->* [Vertex Vertex Vertex ] [ Marko John Nicholas]

www.orientechnologies.com

Load up 2rd level of depth= *:2

TinkerPop technologiessort of “standard” for GraphDB

a lot of free open-source projects

http://tinkerpop.com

www.orientechnologies.com

GraphDB & Blueprints API

OrientGraph graph = new OrientGraph("local:/tmp/db/graph”);

Vertex sheldon = graph.addVertex(null);actor.setProperty("name", "Sheldon");actor.setProperty("surname", "Cooper");

Vertex leonard = graph.addVertex(null);actor.setProperty("name", "Leonard");actor.setProperty("surname", "Hofstadter");

Edge edge = graph.addEdge(null, sheldon, leonard, "annoys");

graph.shutdown();

www.orientechnologies.com

www.orientechnologies.com

Graph example

SQL TRAVERSE

traverse in from Scientist where $depth <= 2

traverse out from 10:1 where $depth <= 5

traverse * from (select from Scientist where name = 'Sheldon') where $depth < 3

www.orientechnologies.com

SQL TRAVERSEselect name from (traverse in from (select from Nailed) where $depth <= 2) where @class <> 'OGraphEdge'

select in.name as name, in.surname as surname from (traverse out from (select from Commoner where name = 'Penny') where $depth <= 4) where label = 'annoys'

www.orientechnologies.com

Always FreeOpen Source Apache 2 license

free for any purposes,even commercials

www.orientechnologies.com

Prof€$$ional$€rvic€$

by a network of companies throughOrient Technologies

support, training, consulting, mentoring

www.orientechnologies.com

www.orientechnologies.com

OrientDBfor Java developers

8 hours

OrientDBMaster Development

14 hours

OrientDBfor SOA

6 hours

OrientDBand the power of graphs

6 hours

OrientDBfor DBA

6 hours

OrientPlanetfor Web Developers

6 hours

Certification Programto be part of the network

do coursesshare revenues for support

work as consultant

www.orientechnologies.com

Contactcommercial@orientechnologies.com

Luca MolinoCommitter of OrientDB andRoma <Meta> Framework

Open Source projects,

Software Architect at Asset Data

www.orientechnologies.com

www.twitter.com/MaDaPHaKa@Rome, Italy

Recommended