Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Graph Database Using Neo4J

939 views

Published on

In this, we discuss about following Points:
1. What is Big -Data
2. Why Graph Database involved?
3. What is Neo4J?
4. Neo4J Cypher Query Language.
5. Spring-Data-Neo4j Sample Application.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Graph Database Using Neo4J

  1. 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. 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. 3. Acknowledgement ➔ Thanks To My Parents. ➔ Thanks To All Who Support Me or Not. ➔ Dedicated To My Teacher “Mr. Kapil Sakhuja”.
  4. 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.
  5. 5. BigData
  6. 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. 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. 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. 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. 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. 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. 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. 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. 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. 15. CREATE ➔ SQL ◆ INSERT INTO User (name, age) values (“James”, 26) ➔ Cypher ◆ CREATE (u:User {name:"James",age:"26"}) RETURN u
  16. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 27. Spring-Data-Neo4j Sample ➔ Please access below link for Spring-Data-Neo4j Sample Application. ◆ https://github.com/harmeetsingh0013/Spring-Data- Neo4j-Example
  28. 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. 29. References ➔ Practical Neo4J By Gregory Jordan Foreword By Jim Webber ➔ http://neo4j.com/top-ten-reasons/ ➔ http://neo4j.com/developer/get-started/

×