Slide 1

Slide 1 text

No More Joins PythonBrasil[10] - 2014 - Porto de Galinhas, PE

Slide 2

Slide 2 text

[email protected] @rochacbruno github.com/rochacbruno brunorocha.org pythonhub.com Who?

Slide 3

Slide 3 text

What is a NOSQL project? * O projeto que não tem UM banco de dados e sim um ambiente de dados formado por multiplos bancos de dados e não apenas SQL! Exemplo de data-stack: Tipo: Relacional Aplicação: Persistencia / BI / Legado / Finances Tipo: Document Aplicação: Coleta de dados, Mobile apps Tipo: Ultra fast key-value Aplicação: Pub/sub, Real time, chats memcached Tipo: In Memory key-value Aplicação: Cache Tipo: Grafo, Document, Object Oriented Aplicação: Coleta de dados Mobile apps Redes sociais Machine Learning Recomendação Redes complexas Data mining OrientDB

Slide 4

Slide 4 text

Who likes to eat peas?

Slide 5

Slide 5 text

GRAPH THEORY 101 G = (V, E) Vertex, Edges Nós e arestas Objetos e links

Slide 6

Slide 6 text

BRUNO PYBR 2014 ORIENT DB PE VERTEX / Vertices / Nós / Objetos / Instâncias.

Slide 7

Slide 7 text

BRUNO PYBR 2014 ORIENT DB PE {“id”: 123, “tipo”: “palestrante”} {“id”: 456, “tipo”: “estado”} {“id”: 789, “tipo”: “banco de dados”} {“id”: 101112, “tipo”: “Mega Evento”} Meta dados

Slide 8

Slide 8 text

BRUNO PYBR 2014 ORIENT DB PE {“id”: 123, “tipo”: “palestrante”} {“id”: 456, “tipo”: “estado”} {“id”: 789, “tipo”: “banco de dados”} {“id”: 101112, “tipo”: “Mega Evento”} Travels to attends to subject in talks about uses Happens in Edge, Aresta, Ligação, Link, Adjacencia

Slide 9

Slide 9 text

BRUNO PYBR 2014 ORIENT DB PE {“id”: 123, “tipo”: “palestrante”} {“id”: 456, “tipo”: “estado”} {“id”: 789, “tipo”: “banco de dados”} {“id”: 101112, “tipo”: “Mega Evento”} Travels to attends to subject in talks about uses Happens in meta dados {“since”: 2014} {“when”: 11/2014} {“tracks”: [ “NoSQL”, “Python”]} {“speaker”: true, “since”: 2009 } {“for”: [“social network”, “machine learning”]} {“track”: “NoSQL”, “date”: 2014-11-07}

Slide 10

Slide 10 text

BRUNO PYBR 2014 ORIENT DB PE {“id”: 123, “tipo”: “palestrante”} {“id”: 456, “tipo”: “estado”} {“id”: 789, “tipo”: “banco de dados”} {“id”: 101112, “tipo”: “Mega Evento”} Travels to attends to subject in talks about uses Happens in complexity {“since”: 2014} {“when”: 11/2014} {“tracks”: [ “NoSQL”, “Python”]} {“speaker”: true, “since”: 2009 } {“for”: [“social network”, “machine learning”]} {“track”: “NoSQL”, “date”: 2014-11-07} RENATO Lives in {“since”: 1990} knows worked with

Slide 11

Slide 11 text

BRUNO PYBR 2014 ORIENT DB PE {“id”: 123, “tipo”: “palestrante”} {“id”: 456, “tipo”: “estado”} {“id”: 789, “tipo”: “banco de dados”} {“id”: 101112, “tipo”: “Mega Evento”} Travels to attends to subject in talks about uses Happens in Path Traverse {“since”: 2014} {“when”: 11/2014} {“tracks”: [ “NoSQL”, “Python”]} {“speaker”: true, “since”: 2009 } {“for”: [“social network”, “machine learning”]} {“track”: “NoSQL”, “date”: 2014-11-07} Lives in {“since”: 1990} knows worked with RENATO

Slide 12

Slide 12 text

A graph database is any storage system that provides index-free adjacency.

Slide 13

Slide 13 text

NEYMAR?

Slide 14

Slide 14 text

Stéphane Paut?

Slide 15

Slide 15 text

Stéphane Paut?

Slide 16

Slide 16 text

GRAPH OBJECT ORIENTED DOCUMENT SQL Language Tinkerpop Blueprints BUILT IN CACHE 1999 MVRB+Tree Open Source Enterprise Edition Community ACID Transaction MIXED Scheme Full/ Less

Slide 17

Slide 17 text

CA 1 master, multiplos slaves replicados sincronamente. AP Se adicionar nós assincronos.

Slide 18

Slide 18 text

150.000 records por segundo em hardware comum.

Slide 19

Slide 19 text

RB-Tree + B+Tree MVRB+Tree

Slide 20

Slide 20 text

> download at: http://www.orientechnologies.com/download/ > tar -zxvf orientdb….tar.gz > cd orientdb-community/ > vim config/orientdb-server-config.xml Edit the configuration file (./config/orientdb-server-config.xml). Add a super-user called "admin". Insert the following line inside the users tags: > cd bin > ./server.sh start | stop To open the console use: > ./console.sh Quick Start:

Slide 21

Slide 21 text

connect remote:localhost root copied_password list databases connect remote:localhost/GratefulDeadConcerts admin admin create class Vegetable create property Vegetable.name string create property Vegetable.color string create property Vegetable.quantity integer create property Vegetable.good_on_pizza boolean classes info class vegetable browse class vegetable select from vegetable create class Animal extends V create class Food extends V create class Environment extends V create class Eat extends E create class Live extends E create vertex Animal set name = “Rabbit” create vertex Food set name = “Carrot” create vertex Environment set name = “Forest” create edge Eat from ( select from Animal where name = 'Rabbit' ) to ( select from Food where name = 'Carrot' ) create edge Live from ( select from Animal where name = 'Rabbit' ) to ( select from Environment where name = 'Forest' ) select expand( out() ) from Animal

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

PyOrient https://github.com/mogui/pyorient $ pip install pyorient

Slide 24

Slide 24 text

client = pyorient.OrientDB("localhost", 2424) # host, port # open a connection (username and password) client.connect("admin", "admin") # create a database client.db_create(“animals”, DB_TYPE_GRAPH, STORAGE_TYPE_MEMORY) # select to use that database client.db_open(“animals”, "admin", "admin")

Slide 25

Slide 25 text

name: rat specie: rodent name: pea color: green name: man specie: human class: Animal class: Food vértice vértice vértice from from to to class: Eat edge class: Eat edge in out out

Slide 26

Slide 26 text

client.command("create class Animal extends V") client.command("insert into Animal ('name', 'specie') values ('rat', 'rodent')") client.query("select * from Animal") [, …] client.command('create class Food extends V') client.command("insert into Food (name, color) values ('pea', 'green')") client.command('create class Eat extends E') eat_edges = client.command(""" create edge Eat from (select from Animal where name in ['rat', ‘man’]) to (select from Food where name = 'pea') """) [edge.out.get() for edge in eat_edges] ['11:0', ‘12:0’] client.record_load(‘11:0’).name 'rat' client.record_load(‘12:0’).name 'man'

Slide 27

Slide 27 text

name: rat specie: rodent name: pea color: green name: man specie: human class: Animal class: Food vértice vértice vértice from from to to class: Eat edge class: Eat edge in out out

Slide 28

Slide 28 text

# I want to know which animals eats peas pea_eaters = client.query( “select expand( in( Eat ) ) from Food where name = ‘pea’” ) for animal in pea_eaters: print animal.rid, animal.name, animal.specie ‘11:0 rat rodent’ ‘12:0 man human’

Slide 29

Slide 29 text

Ispired by: orientengine

Slide 30

Slide 30 text

from orientengine import Vertex, StringProperty from .edges import Eatable, Eater class Animal(Vertex, Eater): # Can eat Out specie = StringProperty() name = StringProperty() class Food(Vertex, Eatable): # Can be eated In color = StringProperty() name = StringProperty() from .vertices import Animal, Food # create some instances (vertices) rat = Animal(specie='rodent', name='rat') man = Animal(specie='human', name='man') pea = Food(color='green', name='pea') # define some links (edges) rat.eats(pea) man.eats(pea, amount=30) # or pea.eaters.extend(rat, man) # Who eats peas? pea.eaters [, , ...] # or Animal.objects(eats=pea) [, , ...]

Slide 31

Slide 31 text

client.command("create class Animal extends V") client.command('create class Food extends V') client.command('create class Eat extends E') eat_edges = client.command(""" create edge Eat from (select from Animal) to (select from Food) """) pea_eaters = client.query( """select expand( in( Eat ) ) from Food WHERE name = ‘pea’ """) class Animal(Vertex, Eater): specie = StringProperty() name = StringProperty() class Food(Vertex, Eatable): color = StringProperty() name = StringProperty() pea = Food(name='pea') for animal in Animal.objects: animal.eats(pea) pea_eaters = pea.eaters # or pea_eaters = Animal.objects(eats=pea) pure PyOrient orientengine Object-Graph-Document-Mapper for PyOrient

Slide 32

Slide 32 text

https://github.com/rochacbruno/OrientEngine

Slide 33

Slide 33 text

http://localhost:2480/ Orient Studio

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content