the 2nd graph database in sv meetup

Post on 14-Apr-2017

147 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Introduction to Cypher Graph Query Language

October 6, 2016Graph Databases in Silicon Valley Meetup

OverviewGoal

Understand the benefits of Cypher query language

Graph Data Models and Query Languages

Basics of Cypher Query Language

Features and Execution Structure

Who am IPh.D Kisung Kim - Chief Technology Officer of Bitnine Global Inc.

Developed a distributed relational database engine in TmaxSoft

Lead the development of a new graph database, Agens Graph in Bitnine Global

Graph Enthusiast !

Graph Data Model and Query Languages ● Property graph model

○ Cypher query language from Cypher○ AQL from ArangoDB○ OrientDB’s SQL dialect

○ Tinkerpop API, a domain specific language, from Titan

● RDF graph model○ W3C standard recommendation for the Semantic Web

○ SPARQL query language

● Facebook’s GraphQL (?)

Property Graph ModelTerminology: Node(vertex) - Entity

Relationships(Edge)Property - AttributeLabel(type) - Group nodes and relationships

person companyworks_for

Name: Kisung KimEmail: kskim@bitnine.net

Name: Bitnine GlobalHomepage: http://bitnine.net

title: CTOTeam: agens graph

Property

Node

Relationship

Very intuitive and easy

to model E-R diagram to property graphs

Cypher● Declarative query language for the property graph model

○ Inspired by SQL and SPARQL○ Designed to be human-readable query language

● Developed by Neo technology Inc. since 2011● Cypher is now evolving

○ Current version is 3.0

● OpenCypher.org○ Participate in developing the query language

OpenCypher.org

http://www.slideshare.net/neo4j/the-opencypher-project-an-open-graph-query-language

Cypher is Human-ReadableFinding all ancestor-descendant pairs in the graph

with recursiveas ( select parent, child as descendant, 1 as level from source union all select d.parent, s.child, d.level + 1 from descendants as d join source s on d.descendant = s.parent ) select * from descendants order by parent, level, descendant ;

SQL

MATCH p=(descendant)-[:Parent*]->(ancestor)RETURN (ancestor), (descendant), length(p)ORDER BY (ancestor), (descendant), length(p)

Cypher

descendant ancestor

Cypher Query ExampleGraph Pattern

Results

Graph Pattern Matching● Graph pattern matching is at the heart of Cypher● Find subgraphs which are matched to the specified graph pattern

○ Subgraph isomorphism

Query Pattern

Graph Data

Graph Pattern● How can we represent graph patterns in a query?

○ Use ASCII art to represent the graph pattern easily

○ Like a diagram

● Node : ( )● Relationship : --> or <-- (with direction),

-- (without direction)● Node label : ( :LABEL_NAME )● Relationship type : -[ :TYPE_NAME ]->

:Actor :MovieACTS_IN

(:Actor)-[:ACTS_IN]->(:Movie)

Graph Pattern● Property

○ Node property: ( { field : value, … } )○ Relationship property: -[ { field : value, … } ]->

● Assign nodes and relations to variables

:Actorname=’TOM’ :Movie (:Actor {name: “TOM”})-[:ACTS_IN]->(:Movie)

ACTS_IN

(a:Actor {name: “TOM”})-[ r:ACTS_IN]->(b:Movie)

Graph PatternRepresent more complicated patterns

:Person :MovieRATED

:PersonRATED

FRIEND

(a:Person)-[:RATED]->(m:Movie)<-[:RATED]-( c:Person),(a)-[:FRIEND]-(c)

Path1

Path2

Path1

Path2

MATCH Clause● Find the specified patterns ● Return matched variables to the next clause

MATCH(a:Person)-[:RATED]->( m:Movie)<-[:RATED]-( c:Person),(a)-[:FRIEND]-(c)

a (node) m (node) c (node)

Results of MATCH clause

Cypher Clause● For reading

○ MATCH / OPTIONAL MATCH

● For updating○ CREATE○ MERGE○ SET

● For filtering○ WHERE

● For handling results○ WITH, RETURN

○ And ORDER BY, LIMIT, SKIP https://s3.amazonaws.com/artifacts.opencypher.org/M02/railroad/Cypher.html

Cypher Query StructurePipelined ExecutionClauses are provided results from the former clause

MATCH

MATCH

RETURN

tom movie

tom movie nicole

tom.name movie.title nicole.name

Clause Chain Result Format

Uniqueness in Pattern Matching● Cypher defines that pattern matching does not match a relationship to be

matched to several relationships in a pattern

● If we want multiple matching, then separate into multiple MATCH clauses

b

a

c

Graph Data Query Pattern

Friend r1:Friend r2:Friend

MATCH (a)-[r1:Friend]->(b), (a)-[r2:Friend]->(c) MATCH (a)-[r1:Friend]->(b)MATCH (a)-[r2:Friend]->(c)

Variable Length Relationship Matching● One of the important features of the Cypher● Finding all people links between two specified persons

Kisung Kim Joshua

MATCH (:person {name: “Kisung Kim”})- [:friends*]->(:person {name: “Joshua”})

MATCH (:person {name: “Kisung Kim”})- [:friends*3..5]->(:person {name: “Joshua”})

Specify the path length 3 to 5?

SummaryQuery database using graph patterns using Cypher

Cyper features

● Graph pattern syntax● Uniqueness restriction of relationship matching● Pipelined execution structure● Variable length path matching

Graph query is much easier than SQL query

Thank youHow do you feel about Graph Database?

top related