Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stored procedure in Neo4j

I wanted to know if there is any Neo4j equivalent of a stored procedure? When I researched this, I came across events, but I found them more like triggers and not stored procedures.

like image 698
Jack Avatar asked Feb 14 '14 12:02

Jack


People also ask

Does Neo4j support stored procedures?

We package our stored procedure code in a jar file which gets specially “compiled” so that it can run safely within Neo4j's kernel. This process is conveniently automated via Maven and, as with Heidegger's broken hammer, we only notice it when it's not working.

What is procedure in Neo4j?

A user-defined procedure is a mechanism that enables you to extend Neo4j by writing customized code, which can be invoked directly from Cypher. Procedures can take arguments, perform operations on the database, and return results.

How can you find out all procedure that are available on your Neo4j instance?

Neo4j comes with a number of built-in procedures. For a list of these, see Operations Manual → Procedures. Users can also develop custom procedures and deploy to the database. See Java Reference → User-defined procedures for details.

Can I use Gremlin with Neo4j?

The TinkerPop Neo4j Gremlin graph implementation supports only embedded graphs or embedded with HA. If you need to connect to a remote Neo4j instance, you'll have to use neo4j-gremlin-bolt.


3 Answers

There are basically two techniques to extend a Neo4j server:

  1. Server plugins enrich the existing REST endpoints and
  2. unmanaged extensions allow to you create new REST endpoints

Both techniques require to write code in JVM (or other JVM language), package a jar file and deploy it to Neo4j server.

like image 132
Stefan Armbruster Avatar answered Oct 12 '22 22:10

Stefan Armbruster


Stored procedures are available as capabilities CALLABLE from the Cypher language since version 3.0

  • A first reference can be found here https://dzone.com/articles/neo4j-30-stored-procedures
  • A remarkable example, showing how graph can be processed in the large through procedure to achieve network clustering and community decetion, here http://www.markhneedham.com/blog/2016/02/28/neo4j-a-procedure-for-the-slm-clustering-algorithm/

EDIT

As Neo4J 3.0 has been released in April'16, the stored procedure became an official, Apache 2.0 licensed, repository.

https://neo4j.com/labs/apoc/

Available procedures range from data manipulation/import to Spatial and complex graph algorithms (es. Page Rank, Dijkstra, Community detection, betweenness centrality , closeness centrality, etc)

like image 40
m.piunti Avatar answered Oct 12 '22 20:10

m.piunti


My answer here does not answer the question directly (Stefan's answer does just fine for that). With that said, if any of you are considering writing server plugins (to get Stored Proc behavior) before your project is actually being used in production (which at the time of this writing is the vast majority of the Neo4j userbase), I strongly recommend not doing so.

Server plugins add architectural complexity to your project. You will require JVM developers to maintain them. Deploying or updating them can be tricky, and the associated source control methodologies are not intuitive. Neo4j doesn't require schema migrations, which makes your job as a developer easier. Adding server plugins will no longer give you that benefit, and since it's not a mainstream use case of Neo4j, you'll be getting little help from the developer community, and improvements and bug fixes related around that function will be given lesser priority from the Neo4j team.

And all that would be for possibly a slight performance boost, or none at all.

"Stored Procedures" (or using server plugins as such) are an important feature to have in the context of performance tuning, but if your team is still two guys in a garage, don't even think about going down this path.

like image 2
marknuzz Avatar answered Oct 12 '22 22:10

marknuzz