SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
Graph Database
Using
Neo4J
By Harmeet Singh(Taara)
(Java EE Developer)
Email: harmeetsingh.0013@gmail.com
Website: http://programmers-nest.com
Blog: http://harmeetsingh13.blogspot.com
Skype: harmeetsingh0013
Contents
➔ Introduction
➔ Big Data
➔ Graph Databases
➔ Graph DB Vs RDBMS
➔ Journey: RDBMS To Graph DB Modeling
➔ Neo4J
➔ Cypher Query
◆ CREATE, MATCH, WHERE, SET, DELETE, RETURN, REMOVE
◆ Relationship
◆ ORDER BY, SKIP, LIMIT, DISTINCT
◆ Aggregation
➔ Spring-Data-Neo4J Sample
➔ Leftover: The things we didn't cover
Acknowledgement
➔ Thanks To My Parents.
➔ Thanks To All Who Support Me or Not.
➔ Dedicated To My Teacher “Mr. Kapil Sakhuja”.
Introduction
➔ Today, we discuss about Graph Database and Why
Graph Databases involved.
➔ How we use Graph Database using Neo4J.
➔ Cypher Query Language for Neo4J.
➔ Spring-Data-Neo4J Sample Application.
BigData
Graph Database
➔ A Graph Database is a set of vertices and
edges.
➔ Graph Databases is to view the data as an
arbitrary set of objects connected by one or
more kinds of relationships.
Graph DB Vs RDBMS
➔ RDBMS limitation on How a relationship is defined
within a relational database?
➔ In RDBMS creating a join table that brings together
two disparate tables is a common practice, doing so
adds a layer of complexity.
Graph DB Vs RDBMS
➔ A join table is created in order to have metadata that
provides properties about relationships between two
tables. When a similar relationship needs to be created
among other tables, yet another join table must be
created.
➔ Graph databases over relational database is to avoid
what might be referred to as “join hell”
Journey: RDBMS to Graph DB Modeling
➔ In RDBMS, the data is collected in form of Tables, and
the Tables are define with Rows And Columns.
➔ The single table contains Multiple Records and these
records are represent to real world Entity.
Journey: RDBMS to Graph DB Modeling
➔ Now, in Graph Database the data represent in the form
of Nodes and One node is compared to one record in
table.
➔ The Node type is compared to Entity.
➔ In Graph DB, we can create easy relationships with
nodes.
Neo4J
Necessity Is The Mother Of Invention
➔ Neo4j began its life in 2000, when Emil Eifrem, Johan
Svensson, and Peter Naubauer.
➔ World’s Best And First Graph Database.
Neo4J
➔ The “j” in Neo4j stands for Java, and the Java
Development Kit (JDK) is required to run it.
➔ Neo aimed to introduce a database that offered a
better way to model, store, and retrieve data while
keeping all of the core concepts—such as ACIDity,
transactions, and so forth—that made relational
databases into a proven commodity.
Cypher Query Language
➔ Cypher is the Declarative Query Language used for
data manipulation in Neo4j.
➔ A Declarative Language is a high-level type of
language in which the purpose is to instruct the
application on what needs to be done or what you
want from the application, as opposed to how to do it.
➔ Cypher is a Case Sensitive Language.
Cypher Query Language
➔ Cypher is a declarative, SQL-inspired language for
describing patterns in graphs. It allows us to describe
what we want to select, insert, update or delete from a
Graph Database without requiring us to describe
exactly how to do it.
➔ Cypher is not yet a standard graph database language
that can interact with other graph database platforms.
CREATE
➔ SQL
◆ INSERT INTO User (name, age) values
(“James”, 26)
➔ Cypher
◆ CREATE (u:User {name:"James",age:"26"})
RETURN u
MATCH
➔ SQL
◆ SELECT * FROM User
◆ SELECT u.name FROM USER u
➔ Cypher
◆ MATCH (u:User) RETURN u
◆ MATCH (u:User) RETURN u.name
WHERE
➔ SQL
◆ SELECT * FROM User u WHERE u.age = 26
➔ Cypher
◆ MATCH (u:User {age:26}) RETURN u
◆ MATCH (u:User) WHERE u.age = 26 RETURN u
SET
➔ SQL
◆ UPDATE User u SET u.age = 26 WHERE u.name
= “James”
◆ ALTER TABLE User ADD address varchar(45)
➔ Cypher
◆ MATCH (u:User {name:"James"}) SET u.age =
26 RETURN u
◆ MATCH (u:User {name:"James"}) SET u.
address = "Moga" RETURN u
DELETE
➔ SQL
◆ DELETE FROM User u WHERE u.name IS NULL
➔ Cypher
◆ MATCH(u:User) WHERE u.name IS NULL DELETE
u
➔ NOTE: If you delete a node that has relationships, you need
to be sure to remove the relationships as well
RETURN
➔ The RETURN is similar to the SELECT statement found
in SQL
➔ SQL
◆ SELECT u.name AS UserName, u.age AS Age
FROM User u
➔ Cypher
◆ MATCH(u:User) RETURN u.name AS UserName,
u.age AS Age
REMOVE
➔ SQL
◆ ALTER TABLE User u DROP COLUMN u.address
WHERE u.name = “James”
➔ Cypher
◆ MATCH(u:User {name:"James"}) REMOVE u.
address RETURN u
Relationships
➔ CREATE Relation
◆ Match (u:User {name:"James"}), (c:Company
{name:"Netsol"}) create (u)-[:EMP]-> (c)
◆ Match (u:User {id:1}), (u1:User {id:2})
create (u)-[:FRIEND {type:"Brothers"}]->
(u1) RETURN u, u1
➔ NOTE: By convention those relationship-types are written
all upper case using underscores between words.
Relationships
➔ MATCH
◆ (node1)-[rel:TYPE]->(node2)
◆ MATCH(u:User) -[rel:FRIEND]-> (u1:User)
RETURN u.name, u1.name, rel.type
◆ MATCH(u:User) -[:FRIEND]-> (u1:User) -[:
FRIEND]-> (u2:User) RETURN u, u1, u2
Relationships
➔ MATCH
◆ MATCH(u:User) -[*]-> (u1:User) RETURN u,
u1
◆ MATCH(u:User) -[*1..5]-> (u1:User) RETURN
u, u1
◆ MATCH(u:User) -[*2]-> (u1:User) RETURN u,
u1
◆ MATCH(u:User) -[:FRIEND*2]-> (u1:User)
RETURN u, u1
DISTINCT, ORDER BY, SKIP, LIMIT
➔ SQL
◆ SELECT DISTINCT u.name FROM User u WHERE
u.age = 25 ORDER BY u.name DESC
OFFSET 0 LIMIT 5
➔ Cypher
◆ MATCH(u:User {age:25}) RETURN
DISTINCT u.name ORDER BY u.name DESC
SKIP 0 LIMIT 5
Aggregation
➔ COUNT
◆ MATCH(u:User {age:25}) RETURN COUNT(u.
name)
➔ COLLECT
◆ MATCH(u:User {age:25}) RETURN COLLECT(u.
name)
➔ NOTE: There are more aggregation functions like
min(), max(), avg() etc.
Spring-Data-Neo4j Sample
➔ Please access below link for Spring-Data-Neo4j Sample
Application.
◆ https://github.com/harmeetsingh0013/Spring-Data-
Neo4j-Example
Leftover: The things we didn’t cover
➔ Graph Theory
➔ Database ACID Operations
➔ Graph DB Modeling
➔ Advance Cypher Query Language
➔ Neo4j Aggregation Functions
➔ Neo4J Native Libraries With Java
➔ Neo4J Rest API
➔ Indexing
References
➔ Practical Neo4J By Gregory Jordan
Foreword By Jim Webber
➔ http://neo4j.com/top-ten-reasons/
➔ http://neo4j.com/developer/get-started/

Contenu connexe

Similaire à Graph Database Using Neo4J

Data Modeling with Neo4j
Data Modeling with Neo4jData Modeling with Neo4j
Data Modeling with Neo4jNeo4j
 
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DBAthens Big Data
 
03 introduction to graph databases
03   introduction to graph databases03   introduction to graph databases
03 introduction to graph databasesNeo4j
 
Change RelationalDB to GraphDB with OrientDB
Change RelationalDB to GraphDB with OrientDBChange RelationalDB to GraphDB with OrientDB
Change RelationalDB to GraphDB with OrientDBApaichon Punopas
 
Introduction to SQL Server Graph DB
Introduction to SQL Server Graph DBIntroduction to SQL Server Graph DB
Introduction to SQL Server Graph DBGreg McMurray
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Robert Schadek
 
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...Databricks
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowKarsten Dambekalns
 
NoSQL, Neo4J for Java Developers , OracleWeek-2012
NoSQL, Neo4J for Java Developers , OracleWeek-2012NoSQL, Neo4J for Java Developers , OracleWeek-2012
NoSQL, Neo4J for Java Developers , OracleWeek-2012Eugene Hanikblum
 
Introduction to Graph Databases
Introduction to Graph DatabasesIntroduction to Graph Databases
Introduction to Graph DatabasesMax De Marzi
 
PGQL: A Language for Graphs
PGQL: A Language for GraphsPGQL: A Language for Graphs
PGQL: A Language for GraphsJean Ihm
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageNeo4j
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDBFitz Agard
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)MongoSF
 
Hands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jHands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jSerendio Inc.
 

Similaire à Graph Database Using Neo4J (20)

Data Modeling with Neo4j
Data Modeling with Neo4jData Modeling with Neo4j
Data Modeling with Neo4j
 
Neo4j (Part 1)
Neo4j (Part 1)Neo4j (Part 1)
Neo4j (Part 1)
 
GraphDatabase.pptx
GraphDatabase.pptxGraphDatabase.pptx
GraphDatabase.pptx
 
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB
 
03 introduction to graph databases
03   introduction to graph databases03   introduction to graph databases
03 introduction to graph databases
 
CouchDB
CouchDBCouchDB
CouchDB
 
Change RelationalDB to GraphDB with OrientDB
Change RelationalDB to GraphDB with OrientDBChange RelationalDB to GraphDB with OrientDB
Change RelationalDB to GraphDB with OrientDB
 
Introduction to SQL Server Graph DB
Introduction to SQL Server Graph DBIntroduction to SQL Server Graph DB
Introduction to SQL Server Graph DB
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...
 
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
NoSQL, Neo4J for Java Developers , OracleWeek-2012
NoSQL, Neo4J for Java Developers , OracleWeek-2012NoSQL, Neo4J for Java Developers , OracleWeek-2012
NoSQL, Neo4J for Java Developers , OracleWeek-2012
 
Neo4j
Neo4jNeo4j
Neo4j
 
AnzoGraph DB - SPARQL 101
AnzoGraph DB - SPARQL 101AnzoGraph DB - SPARQL 101
AnzoGraph DB - SPARQL 101
 
Introduction to Graph Databases
Introduction to Graph DatabasesIntroduction to Graph Databases
Introduction to Graph Databases
 
PGQL: A Language for Graphs
PGQL: A Language for GraphsPGQL: A Language for Graphs
PGQL: A Language for Graphs
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query Language
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)
 
Hands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jHands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4j
 

Dernier

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 

Dernier (20)

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 

Graph Database Using Neo4J

  • 1. Graph Database Using Neo4J By Harmeet Singh(Taara) (Java EE Developer) Email: harmeetsingh.0013@gmail.com Website: http://programmers-nest.com Blog: http://harmeetsingh13.blogspot.com Skype: harmeetsingh0013
  • 2. Contents ➔ Introduction ➔ Big Data ➔ Graph Databases ➔ Graph DB Vs RDBMS ➔ Journey: RDBMS To Graph DB Modeling ➔ Neo4J ➔ Cypher Query ◆ CREATE, MATCH, WHERE, SET, DELETE, RETURN, REMOVE ◆ Relationship ◆ ORDER BY, SKIP, LIMIT, DISTINCT ◆ Aggregation ➔ Spring-Data-Neo4J Sample ➔ Leftover: The things we didn't cover
  • 3. Acknowledgement ➔ Thanks To My Parents. ➔ Thanks To All Who Support Me or Not. ➔ Dedicated To My Teacher “Mr. Kapil Sakhuja”.
  • 4. Introduction ➔ Today, we discuss about Graph Database and Why Graph Databases involved. ➔ How we use Graph Database using Neo4J. ➔ Cypher Query Language for Neo4J. ➔ Spring-Data-Neo4J Sample Application.
  • 6. Graph Database ➔ A Graph Database is a set of vertices and edges. ➔ Graph Databases is to view the data as an arbitrary set of objects connected by one or more kinds of relationships.
  • 7. Graph DB Vs RDBMS ➔ RDBMS limitation on How a relationship is defined within a relational database? ➔ In RDBMS creating a join table that brings together two disparate tables is a common practice, doing so adds a layer of complexity.
  • 8. Graph DB Vs RDBMS ➔ A join table is created in order to have metadata that provides properties about relationships between two tables. When a similar relationship needs to be created among other tables, yet another join table must be created. ➔ Graph databases over relational database is to avoid what might be referred to as “join hell”
  • 9. Journey: RDBMS to Graph DB Modeling ➔ In RDBMS, the data is collected in form of Tables, and the Tables are define with Rows And Columns. ➔ The single table contains Multiple Records and these records are represent to real world Entity.
  • 10. Journey: RDBMS to Graph DB Modeling ➔ Now, in Graph Database the data represent in the form of Nodes and One node is compared to one record in table. ➔ The Node type is compared to Entity. ➔ In Graph DB, we can create easy relationships with nodes.
  • 11. Neo4J Necessity Is The Mother Of Invention ➔ Neo4j began its life in 2000, when Emil Eifrem, Johan Svensson, and Peter Naubauer. ➔ World’s Best And First Graph Database.
  • 12. Neo4J ➔ The “j” in Neo4j stands for Java, and the Java Development Kit (JDK) is required to run it. ➔ Neo aimed to introduce a database that offered a better way to model, store, and retrieve data while keeping all of the core concepts—such as ACIDity, transactions, and so forth—that made relational databases into a proven commodity.
  • 13. Cypher Query Language ➔ Cypher is the Declarative Query Language used for data manipulation in Neo4j. ➔ A Declarative Language is a high-level type of language in which the purpose is to instruct the application on what needs to be done or what you want from the application, as opposed to how to do it. ➔ Cypher is a Case Sensitive Language.
  • 14. Cypher Query Language ➔ Cypher is a declarative, SQL-inspired language for describing patterns in graphs. It allows us to describe what we want to select, insert, update or delete from a Graph Database without requiring us to describe exactly how to do it. ➔ Cypher is not yet a standard graph database language that can interact with other graph database platforms.
  • 15. CREATE ➔ SQL ◆ INSERT INTO User (name, age) values (“James”, 26) ➔ Cypher ◆ CREATE (u:User {name:"James",age:"26"}) RETURN u
  • 16. MATCH ➔ SQL ◆ SELECT * FROM User ◆ SELECT u.name FROM USER u ➔ Cypher ◆ MATCH (u:User) RETURN u ◆ MATCH (u:User) RETURN u.name
  • 17. WHERE ➔ SQL ◆ SELECT * FROM User u WHERE u.age = 26 ➔ Cypher ◆ MATCH (u:User {age:26}) RETURN u ◆ MATCH (u:User) WHERE u.age = 26 RETURN u
  • 18. SET ➔ SQL ◆ UPDATE User u SET u.age = 26 WHERE u.name = “James” ◆ ALTER TABLE User ADD address varchar(45) ➔ Cypher ◆ MATCH (u:User {name:"James"}) SET u.age = 26 RETURN u ◆ MATCH (u:User {name:"James"}) SET u. address = "Moga" RETURN u
  • 19. DELETE ➔ SQL ◆ DELETE FROM User u WHERE u.name IS NULL ➔ Cypher ◆ MATCH(u:User) WHERE u.name IS NULL DELETE u ➔ NOTE: If you delete a node that has relationships, you need to be sure to remove the relationships as well
  • 20. RETURN ➔ The RETURN is similar to the SELECT statement found in SQL ➔ SQL ◆ SELECT u.name AS UserName, u.age AS Age FROM User u ➔ Cypher ◆ MATCH(u:User) RETURN u.name AS UserName, u.age AS Age
  • 21. REMOVE ➔ SQL ◆ ALTER TABLE User u DROP COLUMN u.address WHERE u.name = “James” ➔ Cypher ◆ MATCH(u:User {name:"James"}) REMOVE u. address RETURN u
  • 22. Relationships ➔ CREATE Relation ◆ Match (u:User {name:"James"}), (c:Company {name:"Netsol"}) create (u)-[:EMP]-> (c) ◆ Match (u:User {id:1}), (u1:User {id:2}) create (u)-[:FRIEND {type:"Brothers"}]-> (u1) RETURN u, u1 ➔ NOTE: By convention those relationship-types are written all upper case using underscores between words.
  • 23. Relationships ➔ MATCH ◆ (node1)-[rel:TYPE]->(node2) ◆ MATCH(u:User) -[rel:FRIEND]-> (u1:User) RETURN u.name, u1.name, rel.type ◆ MATCH(u:User) -[:FRIEND]-> (u1:User) -[: FRIEND]-> (u2:User) RETURN u, u1, u2
  • 24. Relationships ➔ MATCH ◆ MATCH(u:User) -[*]-> (u1:User) RETURN u, u1 ◆ MATCH(u:User) -[*1..5]-> (u1:User) RETURN u, u1 ◆ MATCH(u:User) -[*2]-> (u1:User) RETURN u, u1 ◆ MATCH(u:User) -[:FRIEND*2]-> (u1:User) RETURN u, u1
  • 25. DISTINCT, ORDER BY, SKIP, LIMIT ➔ SQL ◆ SELECT DISTINCT u.name FROM User u WHERE u.age = 25 ORDER BY u.name DESC OFFSET 0 LIMIT 5 ➔ Cypher ◆ MATCH(u:User {age:25}) RETURN DISTINCT u.name ORDER BY u.name DESC SKIP 0 LIMIT 5
  • 26. Aggregation ➔ COUNT ◆ MATCH(u:User {age:25}) RETURN COUNT(u. name) ➔ COLLECT ◆ MATCH(u:User {age:25}) RETURN COLLECT(u. name) ➔ NOTE: There are more aggregation functions like min(), max(), avg() etc.
  • 27. Spring-Data-Neo4j Sample ➔ Please access below link for Spring-Data-Neo4j Sample Application. ◆ https://github.com/harmeetsingh0013/Spring-Data- Neo4j-Example
  • 28. Leftover: The things we didn’t cover ➔ Graph Theory ➔ Database ACID Operations ➔ Graph DB Modeling ➔ Advance Cypher Query Language ➔ Neo4j Aggregation Functions ➔ Neo4J Native Libraries With Java ➔ Neo4J Rest API ➔ Indexing
  • 29. References ➔ Practical Neo4J By Gregory Jordan Foreword By Jim Webber ➔ http://neo4j.com/top-ten-reasons/ ➔ http://neo4j.com/developer/get-started/