Book Image

Graph Data Processing with Cypher

By : Ravindranatha Anthapu
Book Image

Graph Data Processing with Cypher

By: Ravindranatha Anthapu

Overview of this book

While it is easy to learn and understand the Cypher declarative language for querying graph databases, it can be very difficult to master it. As graph databases are becoming more mainstream, there is a dearth of content and guidance for developers to leverage database capabilities fully. This book fills the information gap by describing graph traversal patterns in a simple and readable way. This book provides a guided tour of Cypher from understanding the syntax, building a graph data model, and loading the data into graphs to building queries and profiling the queries for best performance. It introduces APOC utilities that can augment Cypher queries to build complex queries. You’ll also be introduced to visualization tools such as Bloom to get the most out of the graph when presenting the results to the end users. After having worked through this book, you’ll have become a seasoned Cypher query developer with a good understanding of the query language and how to use it for the best performance.
Table of Contents (18 chapters)
1
Part 1: Cypher Introduction
4
Part 2: Working with Cypher
9
Part 3: Advanced Cypher Concepts

Working with the UNWIND clause

We saw the usage of FOREACH in the previous section and explored how we can iterate a list and update the graph. But, its usage is limited. If we want to retrieve data from a graph based on the data in a list before we can update the graph, then it is not possible with FOREACH. The UNWIND clause allows us to be able to do this. Also, if we want to return some data while processing a list, then UNWIND is the option to do this.

Let’s take a look at the query we built to add a label in the previous section and build it using UNWIND:

MATCH (p:Patient)
WHERE p.marital IS NULL
WITH collect(p) as nodes
UNWIND nodes as n
SET n:UNKNOWN_STATUS

This does exactly what the FOREACH query did earlier. We find the patients who do not have a marital property set, and then we collect those nodes into a list and unwind that list to process one node at a time.

We can see from the screenshot that we updated 388 nodes, which is exactly what happened when...