change relationaldb to graphdb with orientdb

48
Change Relational DB to Graph DB with OrientDB Speaker : Apaichon Punpas Sponsor By เคอายโปรแกรมเมอไทย โค้ดชิวๆ

Upload: apaichon-punopas

Post on 14-Jul-2015

556 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Change RelationalDB to GraphDB with OrientDB

Change Relational DB to Graph DB with OrientDB

Speaker : Apaichon PunpasSponsor By

เครือข่ายโปรแกรมเมอร์ไทย

โค้ดชิวๆ

Page 2: Change RelationalDB to GraphDB with OrientDB

What is Relational DB ?It is a way of storing information into • table • column • row A table is able relate to other.

Page 3: Change RelationalDB to GraphDB with OrientDB

What is NoSQL ?A NoSQL (often interpreted as Not only SQL) database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases. Motivations for this approach include simplicity of design, horizontal scaling, and finer control over availability.

Page 4: Change RelationalDB to GraphDB with OrientDB

Type of NoSQL

Page 5: Change RelationalDB to GraphDB with OrientDB

Relational vs NoSQL format

EmployeeId FirstName LastName HiredDate PositionId

1 Apaichon Punopas 13/11/2013 1

2 Tony Jar 1/1/2011 3

PositionId PositionName1 Senior Developer2 Developer

Manager3 Actor

{EmployeeId:1 ,FirstName:”Apaichon” ,LastName:”Punopas” ,HiredDate:”2013-11-13” ,PositionId:”#16:0”}

{PositionId:”#16:0”,PositionName:”Senior Developer”}

Employee

Position

Page 6: Change RelationalDB to GraphDB with OrientDB

Relational DB Pros and Cons

Pros Cons

Flexible and well-established. Performance problems with complicated data structures.

Short Learning Curve Lack of support for complex base types, e.g., drawings.

Data access through SQL. SQL is limited when accessing complex data.

Large development efforts and with large databases are well understood.

Knowledge of the database structure is required to create ad hoc queries.

The fundamental structure, i.e., a table, is easily understood and the design and normalization

Locking mechanisms

Page 7: Change RelationalDB to GraphDB with OrientDB

NoSQL Pros and Cons

Pros ConsMostly open source. Immaturity

Horizontal scalability. Possible database administration issues

Support for Map/Reduce Data Relationship Like SQL

No need to develop fine-grained data model. No indexing support (Some DB)

Very fast for adding new data No ACID (Some DB)

No need to changes in code when data structure is modified. Absence of standardization

Ability to store complex data types in a single item of storage.

Page 8: Change RelationalDB to GraphDB with OrientDB

Who are using No SQL ?• All big companies using NoSQL

Page 9: Change RelationalDB to GraphDB with OrientDB

Who are using OrientDB ?THJUG

• Nobody uses Java anymore, I'm nobody

A.K.A

• Nobody uses OrientDB anymore, I'm nobody

Page 10: Change RelationalDB to GraphDB with OrientDB

NoSQL trends

http://news.yahoo.com/nosql-databases-eat-relational-database-191517881.html

Page 11: Change RelationalDB to GraphDB with OrientDB

Database trends

Page 12: Change RelationalDB to GraphDB with OrientDB

Job trends

Page 13: Change RelationalDB to GraphDB with OrientDB

Will NoSQL replace Relational ?

• NoSQL databases eat into the relational database market.

• New venture and startup most start with NoSQL.

• Relational has more used in Enterprise and more features better. It is difficult to replace all in 10 - 20 years. In the future might have new database type again.

Page 14: Change RelationalDB to GraphDB with OrientDB

Why join is suck ?Join Step

• Add relational data into least 2 tables

• select data

• mapping data

• reduce result set

EmployeeId FirstName LastName HiredDate PositionId

1 Apaichon Punopas 13/11/2013 1

2 Tony Jar 1/1/2011 3

PositionId PositionName1 Senior Developer2 Developer

Manager3 Actor

Select e.*,p.PositionName from Employee e INNER Join Position p on e.PositionId = p.PositionId

Page 15: Change RelationalDB to GraphDB with OrientDB

How is OrientDB join ?Join Step

• Add relational data into least 2 tables.

It’s already Join! @rid FirstName LastName HiredDate PositionId

#22:0 Apaichon Punopas 13/11/2013 #23:0

@rid PositionName

#23:0 Senior Developer

select @rid as employeeId, firstName , lastName , positionId.positionName from Employee

Page 16: Change RelationalDB to GraphDB with OrientDB

Welcome to OrientDBLuca Garulli

CEO, Founder

Luca OlivariPresident

www.orientdb.org

Page 17: Change RelationalDB to GraphDB with OrientDB

What is GraphDB ?Graph Theory

G = (V, E)

V = Vertex

E = Edge

Page 18: Change RelationalDB to GraphDB with OrientDB

Certificate of chievementThis%certificate%is%awarded%to%

Attendee Your%understand%Graph%Theory.%

Apaichon Punopas

เครือข่าย โปรแกรมเมอร์ไทย

Page 19: Change RelationalDB to GraphDB with OrientDB

Today OrientDB 2.0 is not only GraphDB

It is Multi-Model Database.

Page 20: Change RelationalDB to GraphDB with OrientDB

Document ModelThe data in this model is stored inside documents. A document is a set of key/value pairs (also referred to as fields or properties) where a key allows access to its value. Values can hold primitive data types, embedded documents, or arrays of other values.

{firstName:”A",lastName:"LA", friends:[{firstName:”A"}

,{firstName:"B" , lastName: “lB”}]

}

Page 21: Change RelationalDB to GraphDB with OrientDB

Graph ModelA graph represents a network-like structure consisting of Vertices (also known as Nodes) interconnected by Edges (also known as Arcs). OrientDB's graph model is represented by the concept of a property graph, which defines the following:Vertex - an entity that can be linked with other Vertices.Edge - an entity that links two Vertices.

Page 22: Change RelationalDB to GraphDB with OrientDB

Support Types• Popular types same as other database such as

boolean , integer ,double , string , binary , etc

• Embleded -> JSON such as {name:”A” , friends:[{name:”B” },name:{“C”}]

• Link -> RecordID

Page 23: Change RelationalDB to GraphDB with OrientDB

ClassA Class is a concept taken from the Object Oriented paradigm. In OrientDB it defines a type of record. It's the closest concept to a Relational DBMS Table. Classes can be schema-less, schema-full, or mixed.

Page 24: Change RelationalDB to GraphDB with OrientDB

Schema Type• Schema-Full: enable the strict-mode at class level

and set all the fields as mandatory

• Schema-Less: create classes with no properties. Default mode is non strict-mode so records can have arbitrary fields

• Schema-Hybrid, called also Schema-Mixed is the most used: create classes and define some fields but leave the record to define own custom fields

Page 25: Change RelationalDB to GraphDB with OrientDB

ClusterA cluster is a place where a group of records are stored. Perhaps the best equivalent in the relational world would be a Table. By default, OrientDB will create one cluster per class. All the records of a class are stored in the same cluster which has the same name as the class. You can create up to 32,767 (2^15-1) clusters in a database.

Page 26: Change RelationalDB to GraphDB with OrientDB

Record IDIn OrientDB each record has its own self-assigned unique ID within the database called Record ID or RID. It is composed of two parts:

• cluster-id is the id of the cluster. Each database can have a maximum of 32,767 clusters (2^15-1)

• cluster-position is the position of the record inside the cluster. Each cluster can handle up to 9,223,372,036,854,780,000 (2^63) records, namely 9,223,372 Trillion of records!

#<cluster-id>:<cluster-position>

Page 27: Change RelationalDB to GraphDB with OrientDB

Inheritance• Class includes inheritance features same as OOP

concept.

Page 28: Change RelationalDB to GraphDB with OrientDB

Index• OrientDB supports 4 kinds of indexes:

Page 29: Change RelationalDB to GraphDB with OrientDB

Security• Support drill down to Record level and support

SSL.

Page 30: Change RelationalDB to GraphDB with OrientDB

Caching• OrientDB has several caching mechanisms that act

at different levels. Look at this picture:

Page 31: Change RelationalDB to GraphDB with OrientDB

FunctionsA Function is an executable unit of code that can take parameters and return a result. Using Functions you can perform Functional programming where logic and data are all together in a central place. Functions are similar to the Stored Procedures of RDBMS.

• can be executed via SQL, Java, REST and Studio

Page 32: Change RelationalDB to GraphDB with OrientDB

TransactionsOrientDB is an ACID compliant DBMS.

A database transaction, by definition, must be atomic, consistent, isolated and durable. Database practitioners often refer to these properties of database transactions using the acronym ACID

Page 33: Change RelationalDB to GraphDB with OrientDB

Hooks (Triggers)• Hook works like a trigger. Hook lets to the user

application to intercept internal events before and after each CRUD operation against records. You can use to write custom validation rules, to enforce security or even to orchestrate external events like the replication against a Relational DBMS.

Page 34: Change RelationalDB to GraphDB with OrientDB

APIOrientDB supports 3 kinds of drivers:

• Native binary remote, that talks directly against the TCP/IP socket using the binary protocol

• HTTP REST/JSON, that talks directly against the TCP/IP socket using the HTTP protocol

• Java wrapped, as a layer that links in some way the native Java driver. This is pretty easy for languages that run into the JVM like Scala, Groovy and JRuby

Page 35: Change RelationalDB to GraphDB with OrientDB

Scalability

Page 36: Change RelationalDB to GraphDB with OrientDB

Programming Language Driver

• Most popular language are supported.

Page 37: Change RelationalDB to GraphDB with OrientDB

SQLMost NoSQL products have a custom query language. OrientDB focuses on standards when it comes to query languages. Instead of inventing "Yet Another Query Language", we started from the widely used and well understood SQL.

Page 38: Change RelationalDB to GraphDB with OrientDB

SQL - Select• select from OUser• select from #10:3• select from [#10:1, #10:3, #10:5]• select from OUser where name like 'l%'• select sum(salary) from Employee where age < 40 group by job• select from Employee where any() like ‘Apa%'• select from china:Customers

Page 39: Change RelationalDB to GraphDB with OrientDB

SQL - Insert• insert into Employee (name, surname, gender) values ('Jay', 'Miner', 'M')

• insert into Employee set name = 'Jay', surname = 'Miner', gender = 'M'

• insert into Employee content {name : 'Jay', surname : 'Miner', gender : 'M'}

Page 40: Change RelationalDB to GraphDB with OrientDB

SQL - Update• update Employee set local = true where city = 'London'

• update Employee merge { local : true } where city = 'London'

Page 41: Change RelationalDB to GraphDB with OrientDB

Delete•delete from Employee where city <> 'London'•delete from [#24:0,#24:1,#24:2]

Page 42: Change RelationalDB to GraphDB with OrientDB

Sub Queryselect from Documentlet $temp = ( select @rid, $depth from ( traverse V.out, E.in from $parent.current ) where @class = 'Concept'

and (id = 'first concept' or id = 'second concept' )

)where $temp.size() > 0

Page 43: Change RelationalDB to GraphDB with OrientDB

TraverseTraverse is a special command that retrieves the connected records crossing the relationships. This command works not only with graph API but at document level. This means you can traverse relationships between invoice and customers without the need to model the domain using the Graph API.

traverse * from #9:1

Page 44: Change RelationalDB to GraphDB with OrientDB

My favourite in OrientDB• I’m favourite many things in OrientDB which never found in other DB.

• insert , update with JSON

• save - automatic insert or update when pass value with @rid

• validate property with regular expression.

• median - I’m got bad performance and develop out of the box with other DB but OrientDB included and fast.

• array and JSON hierarchy - keep array in one field help easily to use with data visualise.

• expand - expand array to horizontal like table , row , column.

Page 45: Change RelationalDB to GraphDB with OrientDB

AppendixPrerequisite

• JVM

Installation

• Download at http://www.orientechnologies.com/download/

• Extract file

• go to directory bin then run server.sh or server.bat

Page 46: Change RelationalDB to GraphDB with OrientDB

AppendixManagement Studio

• by default run on port 2480

• open browser then type http://localhost:2480

Page 47: Change RelationalDB to GraphDB with OrientDB

AppendixConsole

• go to directory bin then run console.sh or console.bat

Page 48: Change RelationalDB to GraphDB with OrientDB

Thank you • Delicious and Enjoy to use