Book Image

Learning Neo4j

By : Rik Van Bruggen
Book Image

Learning Neo4j

By: Rik Van Bruggen

Overview of this book

Table of Contents (18 chapters)
Learning Neo4j
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Where to Find More Information Related to Neo4j
Index

The key attributes of Cypher


In making Cypher, Neo Technology and Andres Taylor (@andres_taylor) set out to create a new query language, specifically for dealing with graph data structures like the ones we store in Neo4j. There were a couple of reasons for doing this, more specifically four attributes that are not available together in any other query language out there.

Let's quickly examine these attributes, as they are quite important to understanding the way Cypher works in Neo4j:

  • Declarative: Cypher is a declarative query language, which is very different from the imperative alternatives out there. You declare the pattern that you are looking for. You effectively tell Cypher what you want, not how to get it. This is crucial, as imperative approaches always suppose that you—as you interact with the database—have the following qualities:

    • A programmer who knows how to tell the database what to do—probably with some procedural logic that would need to be formalized in a program

    • Someone that intimately knows the structure, size, and semantics of the dataset being queried in order for the imperative path to the result set to be optimally formed

    Both assumptions seem to be quite far-fetched and for this reason, many database systems have settled on declarative approaches to querying their data. Structured Query Language (SQL) is of course the most well known example.

  • Expressive: Many people have highlighted that the Cypher syntax is a little bit like ASCII art, and it probably is. With its rounded and square brackets, and the arrows connecting the parts of the pattern, it is very easy to understand how the query language expresses what you are looking for. The reason behind optimizing the syntax for reading is simple and clear: most code gets read far more often than that it gets written. Expressiveness, therefore, is a very interesting attribute for teams working together on a system that relies on the Neo4j graph Database Management System.

  • Pattern Matching: Cypher is a pattern matching query language. This is probably one of the more "graphy" aspects of the language, as it allows people to sketch and draw complex relationships between different entities in the data set quite easily. Humans are actually very good at working with patterns; it tends to be very easy for our brain to work with them. Many people therefore experience cypher as a very easy query language to get started with.

  • Idempotent: When Neo Technology started working on Cypher, the lead architect of the query language, Andres Taylor, set out to do so using Scala, a functional programming language on the Java Virtual Machine. One of the key traits of functional programing environments is that they are supposed to be idempotent. In layman's terms, this means that when you operate a function (or in our case, execute a query) in your algorithm, changes in the data should only happen on the first execution of the function. Multiple executions of the same function over the same data should have no effect. This has some great advantages in functional programs, but also in the Neo4j database, as state change will be expressed idempotently.

Knowing this, we can now explore some of the key operative words in Cypher, and familiarize you with some of these concepts in the real world.