Is it possible to create custom functions in Cypher?

Consider a Neo4J 2.0 Cypher request

MERGE (u:User {id_str:"123"}) ON CREATE SET {giant_params_string_from_twitter_api} ON MATCH SET u.lastSeen = timestamp() RETURN u 

Here I downloaded the user's metadata from Twitter, and if the user does not exist, I insert all of his metadata. If the user already exists, I just change his timestamp.

The Twitter API call required to retrieve the parameters is long and expensive (especially considering that I continue to get the speed limit). And a lot of time node already exists in the database. Here is the best:

 MERGE (u:User {id_str:"123"}) ON CREATE SET get_twitter_params("123") ON MATCH SET u.lastSeen = timestamp() RETURN u 

In ON CREATE, I would like to somehow call a callback to pull this data.

Is there any way to cause the creation of my own function to be used in Cypher?

+1
source share
2 answers

Not yet! However, they are considering ways to implement user-defined functions (UDF), so I don’t think it will be too far.

You might want to check availability before making your request to twitter if this is an expensive call - unfortunately, you will have to do this outside of a single Cypher request.

+1
source

Starting with Neo4j 3.0, you can now write your own functions. However, they are written in Java.

Take a look at this link for more details: https://neo4j.com/developer/procedures-functions/

0
source

Source: https://habr.com/ru/post/1207119/


All Articles