可以在Cypher中创建自定义函数吗? [英] Possible to create custom functions in Cypher?

查看:119
本文介绍了可以在Cypher中创建自定义函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑Neo4J 2.0 Cypher查询

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

在这里,我已经从Twitter下载了用户的元数据,如果该用户不存在,那么我将插入其所有元数据.如果该用户已经存在,那么我只需修改其时间戳即可.

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.

检索参数所需的对Twitter API的调用既长又昂贵(特别是当您考虑到我的速率一直受到限制时).而且该节点已经有很多时间存在于数据库中了.这是宁愿做的事情:

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

在ON CREATE中,我想以某种方式链接回回调以拉出此数据.

In ON CREATE I would like to somehow link back out to a callback to pull down this data.

有什么方法可以调用创建自己的函数供Cypher使用吗?

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

推荐答案

还没有!他们正在考虑实现用户定义函数(UDF)的方法,因此我认为这不会太过遥远.

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

您可能会在向Twitter发出请求之前考虑是否存在,如果那是一个昂贵的通话-不幸的是,您必须在单个Cypher请求之外进行该操作.

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.

这篇关于可以在Cypher中创建自定义函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆