neo4j makes graphs easy

39
Neo4j makes Graphs Easy

Upload: neo4j-the-fastest-and-most-scalable-native-graph-database

Post on 14-Jul-2015

772 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Neo4j Makes Graphs Easy

Neo4j makes Graphs Easy

Page 2: Neo4j Makes Graphs Easy

Overview

Page 3: Neo4j Makes Graphs Easy

Step 1: Data and Relationships

#1

Page 4: Neo4j Makes Graphs Easy

Step 2: Loading your Data into Neo4j

#2

Page 5: Neo4j Makes Graphs Easy

Step 3: Querying your Data

#3a

#3b

Page 6: Neo4j Makes Graphs Easy

Data and RelationshipsFind all the code at https://github.com/kvangundy/GraphDays

NorthWind

Page 7: Neo4j Makes Graphs Easy

What if we used SQL?

Page 8: Neo4j Makes Graphs Easy
Page 9: Neo4j Makes Graphs Easy

Let’s make a Graph

Page 10: Neo4j Makes Graphs Easy

Building Relationships in Graphs

-name

-employeeID

-orderNum

-shippedOn

Page 11: Neo4j Makes Graphs Easy

SOLD

PRODUCT

PART_OF

SUPPLIES

Page 12: Neo4j Makes Graphs Easy

Modeling it as a Graph

Page 13: Neo4j Makes Graphs Easy

What’s Next?

Page 14: Neo4j Makes Graphs Easy

Step 2: Loading your Data into Neo4j

#2

#3

Page 15: Neo4j Makes Graphs Easy

Querying your Data

Cypher Query Language

Page 16: Neo4j Makes Graphs Easy

Basic Query: Who do people report to?

Page 17: Neo4j Makes Graphs Easy

Basic Query: Who do people report to?

MATCH

(e:Employee)<-[:REPORTS_TO]-(sub:Employee)

RETURN

e.employeeID AS managerID,

e.firstName AS managerName,

sub.employeeID AS employeeID,

sub.firstName AS employeeName;

Page 18: Neo4j Makes Graphs Easy

Basic Query: Who do people report to?

Page 19: Neo4j Makes Graphs Easy

Querying your Data

Query Browser

Page 20: Neo4j Makes Graphs Easy

To The Browser!Holy nodes

Batman!

Page 21: Neo4j Makes Graphs Easy

Querying your Data

REST Drivers

Page 22: Neo4j Makes Graphs Easy

REST Drivers

Java

.NET

JavaScript

Python

Ruby

PHP

ANYWHERE…

Page 23: Neo4j Makes Graphs Easy

Python Code

Page 24: Neo4j Makes Graphs Easy

Loading your Data

Page 25: Neo4j Makes Graphs Easy

C S V

Page 26: Neo4j Makes Graphs Easy

CSV Files for Northwind Data

Page 27: Neo4j Makes Graphs Easy

CSV Files for Northwind Data

Page 28: Neo4j Makes Graphs Easy

Step-by-step Creating the Graph

1.Create the core data

2.Create indexes on the data for performance

3.Create the relationships

Page 29: Neo4j Makes Graphs Easy

LOADing the Data

//Create customers

USING PERIODIC COMMIT 1000

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/customers.csv" AS row

CREATE (:Customer {companyName: row.CompanyName, customerID:

row.CustomerID, fax: row.Fax, phone: row.Phone});

//Create products

USING PERIODIC COMMIT 1000

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/products.csv" AS row

CREATE (:Product {productName: row.ProductName, productID: row.ProductID,

unitPrice: toFloat(row.UnitPrice)});

Page 30: Neo4j Makes Graphs Easy

LOADing the Data

// Create suppliers

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/suppliers.csv" AS row

CREATE (:Supplier {companyName: row.CompanyName, supplierID:

row.SupplierID});

// Create employees

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/employees.csv" AS row

CREATE (:Employee {employeeID:row.EmployeeID, firstName: row.FirstName,

lastName: row.LastName, title: row.Title});

Page 31: Neo4j Makes Graphs Easy

LOADing the Data

// Create categories

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/categories.csv" AS row

CREATE (:Category {categoryID: row.CategoryID, categoryName:

row.CategoryName, description: row.Description});

// Create orders

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row

MERGE (order:Order {orderID: row.OrderID}) ON CREATE SET order.shipName =

row.ShipName;

Page 32: Neo4j Makes Graphs Easy

Creating the Indexes

CREATE INDEX ON :Product(productID);

CREATE INDEX ON :Product(productName);

CREATE INDEX ON :Category(categoryID);

CREATE INDEX ON :Employee(employeeID);

CREATE INDEX ON :Supplier(supplierID);

CREATE INDEX ON :Customer(customerID);

CREATE INDEX ON :Customer(customerName);

Page 33: Neo4j Makes Graphs Easy

Creating the Relationships

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row

MATCH (order:Order {orderID: row.OrderID})

MATCH (customer:Customer {customerID: row.CustomerID})

MERGE (customer)-[:PURCHASED]->(order);

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/products.csv" AS row

MATCH (product:Product {productID: row.ProductID})

MATCH (supplier:Supplier {supplierID: row.SupplierID})

MERGE (supplier)-[:SUPPLIES]->(product);

Page 34: Neo4j Makes Graphs Easy

Creating the Relationships

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/products.csv" AS row

MATCH (product:Product {productID: row.ProductID})

MATCH (category:Category {categoryID: row.CategoryID})

MERGE (product)-[:PART_OF]->(category);

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/employees.csv" AS row

MATCH (employee:Employee {employeeID: row.EmployeeID})

MATCH (manager:Employee {employeeID: row.ReportsTo})

MERGE (employee)-[:REPORTS_TO]->(manager);

Page 35: Neo4j Makes Graphs Easy

Creating the Relationships

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row

MATCH (order:Order {orderID: row.OrderID})

MATCH (product:Product {productID: row.ProductID})

MERGE (order)-[relation:PRODUCT]->(product)

ON CREATE SET relation.unitPrice = toFloat(row.UnitPrice), relation.quantity

= toFloat(row.Quantity);

USING PERIODIC COMMIT

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-

contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row

MATCH (order:Order {orderID: row.OrderID})

MATCH (employee:Employee {employeeID: row.EmployeeID})

MERGE (employee)-[:SOLD]->(order);

Page 36: Neo4j Makes Graphs Easy

Recap

Page 37: Neo4j Makes Graphs Easy

What we talked about Today

#1 #2

#3a

#3b

Page 38: Neo4j Makes Graphs Easy

Questions?

Page 39: Neo4j Makes Graphs Easy

Go Forth and Be Graphy.