英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论