如何在gremlin中获取一个名为ID的属性 [英] How to get an attribute named ID in gremlin

查看:757
本文介绍了如何在gremlin中获取一个名为ID的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写gremlin查询时,我得到了奇怪的结果。我可以愉快地使用has函数来获取我节点的大部分属性,例如()。has('name','VerisignCzagExtension')。property('id')将返回v5086。但是,当我尝试使用具有属性ID的has函数时,它永远不会返回true。例如()。has('id','v5086')。property('id')不返回任何结果。任何人都有任何想法,为什么会发生这种情况?



谢谢。

解决方案

在内部,Neo4j将所有ID存储为 java.lang.Long 对象。这是 id 属性的特殊行为。所有其他属性都与其隐含的数据类型一起存储。这就是为什么具有('name','VerisignCzagExtension')工作原因(,因为 name 属性被排除从 id 这个特殊行为)。我假设 v5086 被类型转换为 java.lang.Long ,从而失去了真正的价值。这可以解释有('id','v5086') Gremlin步骤后的零结果。

id 属性是不可变的(不能改变)。如果您需要使用具有 Gremlin步骤使 id 查找顶点,则它看起来像 has('id',5086L)假设顶点 id 5086 >并以 java.lang.Long 值存储。一个额外的 L 用于显式 java.lang.Long 类型转换,Neo4j会假设 java.lang.Integer 如果不添加 L 并且您的Gremlin步骤会再次导致零结果。



最后,您可能想要使用其他命名标识,例如使用键 name 的属性。



希望这有助于。


I'm getting weird results while writing a gremlin query. I can happily use the has function for most of the attributes for my nodes, for example "().has('name', 'VerisignCzagExtension').property('id')" will return v5086. But when I attempt to use the has function with the attribute id it never returns true. for example "().has('id', 'v5086').property('id')" returns no results. Anyone have any idea why this is happening?

Thanks.

解决方案

Internally, Neo4j stores all IDs as java.lang.Long objects. This is a special behavior for id property only. All other properties are stored with their implied data types. That's a reason why has('name', 'VerisignCzagExtension') works (because name property is excluded from this special behavior meant for id). I'm assuming v5086 is being type casted to java.lang.Long, thus losing it's real value. That could explain zero results after a has('id', 'v5086') Gremlin step.

AFAIK, id property is immutable (can't be changed). If you need to make id look ups for vertices using a has Gremlin step, it would look something like has('id', 5086L) assuming that the vertex id is 5086 and is being stored as a java.lang.Long value. An extra L is for explicit java.lang.Long type-casting, Neo4j would assume java.lang.Integer if you don't add that L and your Gremlin step would result in zero results again.

Finally, you might want to call your named ID something else, like a property with key name.

Hope this helps.

这篇关于如何在gremlin中获取一个名为ID的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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