Possible to create custom functions in Cypher?

こ雲淡風輕ζ 提交于 2019-12-11 09:17:23

问题


Consider the Neo4J 2.0 Cypher query

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've downloaded the user's metadata from Twitter, and if the user doesn't exist, then I insert all of his metadata. If the user already exists, then I just modify his timestamp.

The call out to Twitter API needed to retrieve the params is long and expensive (especially when you consider that I keep getting rate limited). And a lot of time the node already exists in the database. Here's what would rather do:

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 link back out to a callback to pull down this data.

Is there any way to call create my own function to be used in Cypher?


回答1:


Not yet! They're considering ways of implementing user defined functions (UDFs), though, so I don't think it will be too far out.

You might consider checking for existence before making your request to the twitter, if that is the expensive call--unfortunately you'd have to do that outside of your single Cypher request.




回答2:


As of Neo4j 3.0, you can now write your own functions. They are however written in Java.

Look into this link for more details: https://neo4j.com/developer/procedures-functions/



来源:https://stackoverflow.com/questions/20354408/possible-to-create-custom-functions-in-cypher

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!