Graph Databases

A Brief Introduction

Graph Data Model

Node :: Row

Person

Name: Jennifer Doe

Age: 38

Phone: 5558675309

TYPE :: Schema/table

ATTRIBUTES :: COLUMNS

Graph Data Model

EDGE

Person

Name: Jennifer Doe

Age: 38

Phone: 5558675309

TYPE

ATTRIBUTES

Person

Name: Jane Doe

Age: 12

Phone: 5558426060

Is_Mother_Of

Since: 07/07/2005

HasSoleCustody: True

Graph Data Model

Person

Name: Jennifer Doe

Age: 38

Phone: 5558675309

Person

Name: Jane Doe

Age: 12

Phone: 5558426060

Is_Mother_Of

Since: 07/07/2005

HasSoleCustody: True

Is_Daughter_Of

Since: 07/07/2005

IsOnlyChild: False

"Real" Example Graph

Graph database use cases

Social Networks

Ecommerce Real-time recommendations

Graph database Products

features

  • Directed Property Graph Model, Schema-optional
  • Community & Enterprise Versions
  • ACID Compliance
  • Web-Based GUI
  • Drivers for most popular languages
  • Most popular Graph DB
  • Oldest Graph DB
  • Proprietary query language: Cypher
  • Community-edition missing key features
  • License prohibits commercial use of community edition
  • Multi-model: Document, Key-Value, Object
  • Nicer Web UI
  • SQL-like query language
  • Community-edition has HA, Replication, & Security
  • Permissive License for Commercial Usage

$(whoami)

Jett Durham

Software Engineer at SNT Media in Wichita, KS

DevICT Slack: thejettdurham

Twitter: thejettdurham

GitHub: thejettdurham

Enter Graph Databases

Anyone already familiar?

We know relational databases, right?

Data as rows in tables

Relationships by key reference

powerful

Simple

Flexible

Expressive

robust

ubiquitous

...but

Relationship-first model

"whiteboard" model

organizational mapping

Querying through relationships

SELECT DATEADD(day,-1,pxd_upd_date),

pbd_prod_code,

psd_stk_qty+psd_booked_qty,

IFNULL(CONCAT(CONCAT(TRIM(TRAILING ' ' FROM P.pbd_prod_name),

CASE LENGTH(CONVERT(VARCHAR(6), P.pbd_prod_ptr))

WHEN '5' THEN

CASE

WHEN CONVERT(SQL_INTEGER,SUBSTRING(CONVERT(VARCHAR(6),P.pbd_prod_ptr),3)) <= 700

THEN

(SELECT TRIM(TRAILING ' ' FROM A.aca_cu_name)

FROM admin.sffaca_details A

WHERE A.aca_cu_no=CONCAT('PTX0', SUBSTRING(CONVERT(VARCHAR(6), P.pbd_prod_ptr),1,2))

AND A.aca_addr_no=CONVERT(SQL_INTEGER,SUBSTRING(CONVERT(VARCHAR(6), P.pbd_prod_ptr),3)))

ELSE

(SELECT TRIM(TRAILING ' ' FROM aca_txt_l1)

FROM admin.sffaca_other C

WHERE C.aca_cu_no=CONCAT('PTX0', SUBSTRING(CONVERT(VARCHAR(6), P.pbd_prod_ptr),1,2))

AND C.aca_addr_no=CONVERT(SQL_INTEGER,SUBSTRING(CONVERT(VARCHAR(6), P.pbd_prod_ptr),3)))

END

WHEN '6' THEN

CASE

WHEN CONVERT(SQL_INTEGER,SUBSTRING(CONVERT(VARCHAR(6),P.pbd_prod_ptr),4)) <= 700

THEN

(SELECT TRIM(TRAILING ' ' FROM A.aca_cu_name)

FROM admin.sffaca_details A

WHERE A.aca_cu_no=CONCAT('PTX', SUBSTRING(CONVERT(VARCHAR(6), P.pbd_prod_ptr),1,3))

AND A.aca_addr_no=CONVERT(SQL_INTEGER,SUBSTRING(CONVERT(VARCHAR(6), P.pbd_prod_ptr),4)))

ELSE

(SELECT TRIM(TRAILING ' ' FROM aca_txt_l1)

FROM admin.sffaca_other C

WHERE C.aca_cu_no=CONCAT('PTX', SUBSTRING(CONVERT(VARCHAR(6), P.pbd_prod_ptr),1,3))

AND C.aca_addr_no=CONVERT(SQL_INTEGER,SUBSTRING(CONVERT(VARCHAR(6), P.pbd_prod_ptr),4)))

END

END),

CONCAT(' ', CASE P.pbd_prod_unit WHEN 'Single' THEN '' ELSE P.pbd_prod_unit END)),

CONCAT(TRIM(TRAILING ' ' FROM P.pbd_prod_name),

CONCAT(' ', CASE P.pbd_prod_unit WHEN 'Single' THEN '' ELSE P.pbd_prod_unit END))) AS Description,

(SELECT TOP 1 DATEADD(day,-1, A.bsj_putaway_date)

FROM admin.sffbsj A

WHERE A.bsj_prod_ptr=P.pbd_prod_ptr

AND A.bsj_type=1

ORDER BY A.bsj_move_date DESC, A.bsj_move_time DESC),

pbd_prod_pack,

pbd_vat_code,

pbd_split_price,

pbd_trade_price,

pbd_retail_price,

pbd_layer_qty,

pbd_pallet_size,

pxd_ean_code,

pbd_maj_grp,

pbd_min_grp,

pxd_flags_1,

pxd_flags_2,

pbd_prod_ptr,

CASE pbd_prod_unit WHEN 'Single' THEN '' ELSE pbd_prod_unit END,

psd_po_qty from admin.sffpbd P

LEFT JOIN admin.sffpsd S

ON P.pbd_prod_ptr=S.psd_prod_ptr

LEFT JOIN admin.sffpxd_details D

ON P.pbd_prod_ptr=D.pxd_prod_ptr

WHERE psd_stk_qty+psd_booked_qty+psd_po_qty>0

ORDER BY pbd_maj_grp ASC,

pbd_min_grp ASC,

pbd_prod_name ASC

JOIN

DIstinct

Union

subqueries

IT Operations

overview

  • Relational Databases: The Bad Parts
  • Graph Databases
  • Graph Data Model
  • Graph Database Use Cases
  • Graph Database Products

Graph Databases

By Jett Durham

Graph Databases

  • 486
Loading comments...

More from Jett Durham