查询图数据库以获取属于相同类型顶点的两个值

huangapple go评论54阅读模式
英文:

Query graph db for two values belonging to same type of vertex

问题

Sure, here is the translated Gremlin query:

g.V().has('Parts', '~id', 'ABCD')
.has('Parts', '~id', 'PQRS').values()

Please note that I've removed the HTML entities for single quotes ('') in your query to make it a valid Gremlin query.

英文:

I want to query in Amazon Neptune graph db two values belonging to same type of vertex. How can I achieve this in Gremlin ?

e.g.

If we write a query in sql it would look like this -

select * from table where id in ('ID1', 'Id2')
%%gremlin explain

g.V().has('Parts', '~id', 'ABCD')
.has('Parts', '~id', 'PQRS').values()

答案1

得分: 0

基于 SQL 示例,等价的 Gremlin 代码如下:

g.V().has('Parts', '~id',within( 'ABCD','PQRS')).values()

然而,如果 ~Id 是实际的顶点 ID,则可以直接进行如下操作:

g.V().has('Parts', id, within( 'ABCD','PQRS')).values()

但是,鉴于 ID 是唯一的,如果您知道它应该是该类型,就不需要检查标签:

g.V().hasId('ABCD','PQRS').values()

甚至只需

g.V('ABCD','PQRS').values()
英文:

Based on the SQL example, the equivalent Gremlin would be:

g.V().has('Parts', '~id',within( 'ABCD','PQRS')).values()

However, if ~Id is the actual vertex ID, then you can just do:

g.V().has('Parts', id, within( 'ABCD','PQRS')).values()

but given an ID is unique, you don't need to check the label if you know it should be of that type:

g.V().hasId('ABCD','PQRS').values()

or even just

g.V('ABCD','PQRS').values()

huangapple
  • 本文由 发表于 2023年4月19日 19:01:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76053715.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定