Neo4j Cypher is a very useful neo4j transform available within HOP. This transform allows you to execute any Cypher through the Neo4j Bolt protocol using the Java driver. Both reading and writing are supported. You can even call procedures and get the output using this transform.
In this article we will consider a simple example that pulls data and pushes into neo4j with the help of Neo4j Output transform step.
Transforms involve in current example-
DataGrid - more information on this can be found here - https://hop.apache.org/manual/latest/pipeline/transforms/datagrid.html
You can replace DataGrid with CSV, EXCEL or any other data source as per your requirement.
Neo4j Cypher - more information on this can be found here-https://hop.apache.org/manual/latest/pipeline/transforms/neo4j-cypher.html
UNWIND Example:
Step 2 - Create sample data using Data Grid
Step 3 - Edit the Neo4j Cypher Transform
In this example, we will always use the same cypher statement and this allows us to group input data so we can use UNWIND which will dramatically increase the performance.
Step 1- Create Metadata - For information on how to connect HOP to Aura , Please take a look at this article: Getting Started with Apache HOP: Download , Install and Aura Connection Configuration
Step 2- Create sample data using DataGrid
- Click on File->New->Pipeline
- Left Click anywhere to start
- A popup will appear, search for Data Grid
- Left click on Data Grid and click on Edit
- Under Meta tab add the metadata for your sample data , In the attached example we are using 4 fields so Meta tab will look like below:
- Now, as Metadata is in place, Switch to Data tab and add some data for the corresponding columns.
- Click on Preview to see if records look ok to you and move to step 2
Step 3- Edit the Neo4j Cypher Transform
- Left click anywhere on the screen and search for Neo4j Cypher.
- Now connect DataGrid and Neo4j Cypher transform with a hop, this can be done by left clicking on DataGrid->Create hop and drag that to Neo4j Cypher transform step
- The first thing we need to do is collect all the input rows (mapped to parameter values) into a values map (on the Options tab). Make sure you check the checkbox "Collect parameter values map" and give the input list a name(Replace events with the name of your choice):
- Parameters tab will look like below:
Step 4- Construct Cypher Statement
- The parameters you want to pass to the Cypher statement are listed on the Parameters tab.Finally, we can construct the Cypher statement itself:
UNWIND $events AS event MERGE (y:Year { year: event.year }) MERGE (y)<-[:IN]-(e:Event { id: event.id }) RETURN e.id AS x ORDER BY x
- Click on OK and you can now run the pipeline and it will add the data to Neo4j Aura database.
Comments
0 comments
Please sign in to leave a comment.