Cypher Query Language

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Cypher is a declarative graph query language that allows for expressive and efficient querying and updating of a property graph. Cypher is a relatively simple but still very powerful language. Very complicated database queries can easily be expressed through Cypher. This allows users to focus on their domain instead of getting lost in database access.[1]

Cypher was originally created by Neo Technology for its graph database Neo4j, but was opened up through the openCypher project in October 2015[2] and has since been adopted by several other graph database vendors, including SAP HANA[3] and AgensGraph.[4]

Graph Model[edit]

Cypher is based on the Property Graph Model, which in addition to the standard graph elements of nodes and edges (which are called relationships in Cypher) adds labels and properties as concepts. Nodes may have zero or more labels, while each relationship has exactly one relationship type.[5] Nodes and relationships also have zero or more properties, where a property is a key-value binding of a string key and some value from the Cypher type system.

Type System[edit]

The Cypher type system is detailed in a Cypher Improvement Proposal (CIP),[6] and contains the following types: nodes, relationships, paths, maps, lists, integers, floating-point numbers, booleans, and strings.

Syntax[edit]

Cypher contains a variety of clauses. Among the most common are: MATCH and WHERE. These functions are slightly different than in SQL. MATCH is used for describing the structure of the pattern searched for, primarily based on relationships. WHERE is used to add additional constraints to patterns.[7] For example, the below query will return all movies where an actor named 'Nicole Kidman' have acted, and that was produced before a certain year (sent by parameter):

    MATCH (nicole:Actor {name: 'Nicole Kidman'})-[:ACTED_IN]->(movie:Movie)
    WHERE movie.year < $yearParameter
    RETURN movie

Cypher additionally contains clauses for writing, updating, and deleting data. CREATE and DELETE are used to create and delete nodes and relationships. SET and REMOVE are used to set values to properties and add labels on nodes. It should be noted that nodes can only be deleted when they have no other relationships still existing. For example:[7]

    MATCH (start:Content)-[:RELATED_CONTENT]->(content:Content)
    WHERE content.source = 'user'
    OPTIONAL MATCH (content)-[r]-()
    DELETE r, content

Standardisation[edit]

With the openCypher project, an effort was started to standardise Cypher as the query language for graph processing. One part of this process is the First openCypher Implementers Meeting (oCIM), which was first announced in December 2016.[8][9]

See also[edit]

  • SPARQL, another declarative query language for querying graph data
  • OpenCypher, an initiative by Neo Technology and others to extend the use of Cypher to other graph databases[10]

References[edit]

  1. ^ "Cypher Introduction". Neo Technology. Retrieved January 31, 2017. 
  2. ^ "Meet openCypher: The SQL for Graphs - Neo4j Graph Database". Neo4j Graph Database. 2015-10-21. Retrieved 2017-01-31. 
  3. ^ "Graph Processing with SAP HANA 2". https://blogs.sap.com. Retrieved 2017-01-31.  External link in |website= (help)
  4. ^ "Bitnine AgensGraph". bitnine.net. Retrieved 2017-01-31. 
  5. ^ "Property Graph Model". GitHub. Retrieved 2017-01-31. 
  6. ^ "Cypher Type System". GitHub. Retrieved 2017-01-31. 
  7. ^ a b "Neo4j 3.1.1 manual - MATCH clause". Neo Technology. Retrieved January 31, 2017. 
  8. ^ "openCypher Implementers Meeting · openCypher.org". www.opencypher.org. Retrieved 2017-01-31. 
  9. ^ "oCIM announcement on openCypher Google Groups". groups.google.com. Retrieved 2017-01-31. 
  10. ^ http://neo4j.com/blog/open-cypher-sql-for-graphs/