Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gremlin 只运行一次副作用_Gremlin - Fatal编程技术网

Gremlin 只运行一次副作用

Gremlin 只运行一次副作用,gremlin,Gremlin,我得到一个很小的图表,如: g.addV('person').property(id, 'p1').property('name', 'mark') g.addV('person').property(id, 'p2').property('name', 'mark') g.addV('person').property(id, 'p3').property('name', 'jack') g.addV('person').property(id, 'p4').property('name',

我得到一个很小的图表,如:

g.addV('person').property(id, 'p1').property('name', 'mark')
g.addV('person').property(id, 'p2').property('name', 'mark')
g.addV('person').property(id, 'p3').property('name', 'jack')
g.addV('person').property(id, 'p4').property('name', 'steve')

g.addE('knows').from(V('p1')).to(V('p2')).property('since', 2001)
g.addE('knows').from(V('p1')).to(V('p3')).property('since', 2010)
g.addE('knows').from(V('p2')).to(V('p3')).property('since', 2012)
g.addE('knows').from(V('p3')).to(V('p4')).property('since', 2019)
我想提交一个查询以满足以下两个要求:

  • 获得了“自”大于2005年的所有优势
  • 过滤这些边,找出
    inV
    中的
    p1
    的朋友
到目前为止,我只能编写以下查询:

g.E().hasLabel('knows').has('since', gt(2005)).
    sideEffect(
    V('p1').out().aggregate('friends')).
    where(inV().where(within('friends')))
查询结果如预期:

gremlin>     g.E().hasLabel('knows').has('since', gt(2005)).
......1>       sideEffect(
......2>       V('p1').out().aggregate('friends')).
......3>       where(inV().where(within('friends')))
==>e[26][p1-knows->p3]
==>e[27][p2-knows->p3]
问题是
sideEffect
步骤运行了三次,我只想运行一次。

sideEffect()
运行的次数与遍历程序通过它的次数相同。您可以
profile()

gremlin> g.E().hasLabel('knows').has('since', gt(2005)).
......1>   sideEffect(V('p1').out().aggregate('friends')).
......2>   where(inV().where(within('friends'))).profile()
==>Traversal Metrics
Step                                                               Count  Traversers       Time (ms)    % Dur
=============================================================================================================
TinkerGraphStep(edge,[~label.eq(knows), since.g...                     3           3           0.180    10.58
TraversalSideEffectStep([TinkerGraphStep(vertex...                     3           3           0.859    50.48
  TinkerGraphStep(vertex,[p1])                                         3           3           0.234
  VertexStep(OUT,vertex)                                               6           6           0.134
  AggregateStep(friends)                                               6           6           0.226
TraversalFilterStep([EdgeVertexStep(IN), Profil...                     2           2           0.662    38.95
  EdgeVertexStep(IN)                                                   3           3           0.036
  WherePredicateStep(within([friends]))                                                        0.126
                                            >TOTAL                     -           -           1.702        -
g.E()
在给定过滤器的情况下生成3个遍历器,因此给
sideEffect()
三个遍历器,这意味着该步骤将执行三次。要使它在需要将这3个减为1的情况下执行,您可以使用
fold()
将这三个值收集到一个列表中,然后在
sideEffect()之后展开该列表。

所以,我认为这是对你问题的直接回答。如果我再深入一点,我想知道你在这里描述的复杂性是否有原因。如果您想找到表示“p1”的朋友在“2005”之后的传入边的边,那么我认为这可以通过以下方式实现:

gremlin> g.V('p1').out('knows').inE('knows').has('since',gt(2005))
==>e[5][p1-knows->p3]
==>e[6][p2-knows->p3]
sideEffect()
的运行次数与遍历程序通过它的次数相同。您可以
profile()

gremlin> g.E().hasLabel('knows').has('since', gt(2005)).
......1>   sideEffect(V('p1').out().aggregate('friends')).
......2>   where(inV().where(within('friends'))).profile()
==>Traversal Metrics
Step                                                               Count  Traversers       Time (ms)    % Dur
=============================================================================================================
TinkerGraphStep(edge,[~label.eq(knows), since.g...                     3           3           0.180    10.58
TraversalSideEffectStep([TinkerGraphStep(vertex...                     3           3           0.859    50.48
  TinkerGraphStep(vertex,[p1])                                         3           3           0.234
  VertexStep(OUT,vertex)                                               6           6           0.134
  AggregateStep(friends)                                               6           6           0.226
TraversalFilterStep([EdgeVertexStep(IN), Profil...                     2           2           0.662    38.95
  EdgeVertexStep(IN)                                                   3           3           0.036
  WherePredicateStep(within([friends]))                                                        0.126
                                            >TOTAL                     -           -           1.702        -
g.E()
在给定过滤器的情况下生成3个遍历器,因此给
sideEffect()
三个遍历器,这意味着该步骤将执行三次。要使它在需要将这3个减为1的情况下执行,您可以使用
fold()
将这三个值收集到一个列表中,然后在
sideEffect()之后展开该列表。

所以,我认为这是对你问题的直接回答。如果我再深入一点,我想知道你在这里描述的复杂性是否有原因。如果您想找到表示“p1”的朋友在“2005”之后的传入边的边,那么我认为这可以通过以下方式实现:

gremlin> g.V('p1').out('knows').inE('knows').has('since',gt(2005))
==>e[5][p1-knows->p3]
==>e[6][p2-knows->p3]

是的,我可以提到我使用的数据集的大小。由于我使用的gremlin服务提供了edge“knows”的“since”属性索引,有1M条边,在“2015”之前过滤后,大约有10k条边。“朋友”的数量约为300,因此我认为如果我可以利用边缘属性索引,效果会更好。您使用的是哪种图形支持这样的边缘索引查找?我使用的是默认支持属性索引的图形。有趣的-我不确定我能想出另一个这样的全局索引查找的图形是的,我可以提到我使用的数据集的大小。由于我使用的gremlin服务提供了edge“knows”的“since”属性索引,有1M条边,在“2015”之前过滤后,大约有10k条边。“朋友”的数量约为300,因此我认为如果我可以利用边缘属性索引,效果会更好。您使用的是哪种支持边缘索引查找的图形?我使用的是默认支持属性索引的图形。有趣的-我不确定我能想出另一种类似全局索引查找的图形