创建复杂的gremlin-java查询 [英] create complex gremlin-java query
问题描述
我在泰坦图数据库中实现了模型,其关系如下所示:
I have model implemented in titan graph database with relations presented below:
[A] ---(e1)---> [B] <---(e2)--- [C] ---(e3)---> [D]
| | | | | | |
prop:id | prop:number | | label:e3 |
| | prop:id |
label:e1 label:e2 prop:number
prop:prop1
A
和B
是主要顶点"(例如用户),B
和C
顶点是不太重要的顶点",用于描述与用户相关的某些数据.
A
and B
are "main vertices" (for example users), vertices B
and C
are "less important vertices" describing some data connected with users.
查询算法的输入是顶点A
的属性id
.
The input for the query algorithm is property id
of vertex A
.
我想找到所有以上述方式与A
连接的顶点D
.此外,我想记住A
和B
之间的边e1
的属性prop1
.
I want to find all such vertices D
, that are connected with A
in the manner shown above. What's more I want to remember the property prop1
of the edge e1
between A
and B
.
更准确地说,我想高效地检索对(prop1, numberD)
,其中prop1
是A -> B
之间的边的属性(如果边缘具有此属性),而numberD
是
More precisely, I want to efficiently retrieve pairs (prop1, numberD)
where prop1
is the property of edge between A -> B
(if the edge has this property), and numberD
is the property number
from D
.
我不知道如何有效地执行此查询.
I don't know how to efficiently implement this query.
很容易只检索顶点D
(使用GremlinPipes
):
It is easy to retrieve only vertices D
(using GremlinPipes
):
pipe
.start(startVertex)
.outE("e1")
.inV().hasProperty("number")
.inE("e2")
.outV().hasProperty("id")
.outE("e3")
.inV().hasProperty("number");
但是当我还需要获得边缘e1
并将其与顶点D
匹配时,就会出现问题.
我试图分别计算所有这些步骤,但是效率似乎很低.
But problems occur when I need to get also edges e1
and match them with vertices D
.
I tried to compute all these steps separately, but is seems to be very inefficient.
您对使用gremlin-java或gremlin-groovy实施此方法(可能使用多个查询)有任何建议吗? 谢谢!
Do you have any suggestions how to implement this (maybe using several queries) using gremlin-java or gremlin-groovy? Thanks!
推荐答案
看看此处描述的模式匹配模式:
Take a look at the Pattern Match Pattern described here:
https://github.com/tinkerpop/gremlin/wiki/Pattern-匹配模式
startVertex.outE('e1').as('e')
.inV().hasProperty('number').inE("e2")
.outV().hasProperty("id")
.outE("e3")
.inV().hasProperty("number").as('d')
.table(t)
这应该提供地图的迭代器
This should give an iterator of maps
[e:e1, d:D]
从每张地图中,您都可以轻松提取感兴趣的属性.
From each of these maps, you can easily extract the properties you are interested in.
这篇关于创建复杂的gremlin-java查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!