Building custom Functions and Procedures
Extend Neo4j with your own Java code. Write, test, package and deploy a user-defined function, procedure and aggregation function, then call them from Cypher.
In this 2-hour course, you will learn
Building custom Functions and Procedures teaches you to extend Neo4j with your own Java code. In around 90 minutes you will write a sentiment scoring plugin, test it, package it as a jar, and call it from CypherNeo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it. as if it shipped with the database.
Neo4j ships with a large library of functions and procedures, and the Cypher language covers most of what you need. Sometimes it does not. You may want to score text at the moment it is loaded, apply a rule that is awkward to express in Cypher, or reuse a Java library that already solves your problem. A user-defined function or procedure lets you do that inside the database, next to the data, with no extra round trip from your application.
Functions, Procedures and Aggregations
Choose between a user-defined function, a procedure and an aggregation function, and write each one with the Neo4j Java annotations.
Test Before You Deploy
Test your plugin with an in-process Neo4j instance from neo4j-harness, so a failing function is caught by Maven and not by a running database.
Read and Write Modes
Declare the mode a procedure runs in, read and write graph data through the injected transaction, and return rows with YIELD.
Packaging and Deployment
Build a shaded jar, keep the Neo4j API at provided scope, and install the plugin with the allowlist setting that makes it callable.
Where Plugins Run
Know what it means for custom code to share the database JVM, and what belongs in a plugin and what does not.
2 modules, 1 hour 30 minutes.
Who this course is for
This course is for developers who write Java and know basic CypherNeo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it.. If you are new to Cypher, take Cypher Fundamentals first. You should be comfortable reading a Maven
pom.xmland running commands in a terminal. You don't need any experience with the Neo4j Java internals.What you will build and do
You will work in a GitHub Codespace that has Java, Maven and a local Neo4j instance ready to use. You will build one plugin and extend it in each lesson.
First, you will write a function that turns a sentiment score into a labelA tag on a node that groups it with other nodes of the same kind. A node can carry more than one., build the jar, deploy it and call it from CypherNeo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it.. You will then write a function that scores text with the VADER sentiment library, and make a set of tests pass using an in-process Neo4j instance.
Next, you will write a procedure that reads headlines from the graph and writes a score back to each one, and an aggregation function that picks the most negative headline for each stock. You will finish by learning where plugins run, what the allowlist setting does, and which kinds of work belong in a plugin and which do not.
Where to go next
To call your plugin from an application, take Using Neo4j with Java. The Neo4j Java Reference covers the other extension points, including security plugins and unmanaged extensions.