【问题标题】:Can Gremlin P.eq accept a Vertex?Gremlin P.eq 可以接受顶点吗?
【发布时间】:2021-05-03 00:11:52
【问题描述】:

我正在尝试应用 Element Existence recipe 来仅插入一个被认为是“有效”(而不是“过期”)的边缘:

def to = __.V(member).hasLabel('Member')

gts.V(group).hasLabel('Group')
  .coalesce(
    __.outE('Includes').hasNot('ttl.end').where(__.inV().is(P.eq(to))),
    __.addE('Includes').to(to).property('ttl.start', timestamp)
  )
  .next()

我的期望是合并将选择没有ttl.end 属性的现有边并入射到相同的to 顶点,或者插入新边。但是,无论如何总是会插入一条新边。我将此解释为表明第一个 subtraversal 与现有的活动边缘不匹配,但我不知道为什么。谓词 P.eq 是否适用于 Traversal<?, Vertex> 参数?如果不是,那么“边缘在顶点to 的终点位置”的正确说法是什么?

个人资料(我注意到IsStep 没有遍历器,我将其解释为不匹配):

Step                                                               Count  Traversers       Time (ms)    % Dur
=============================================================================================================
TinkerGraphStep(vertex,[08f8c62d-5429-40e6-84b7...                     1           1           0.135    10.93
CoalesceStep([[VertexStep(OUT,[Includes],edge),...                     1           1           0.781    63.17
  VertexStep(OUT,[Includes],edge)                                      2           2           0.025
  NotStep([PropertiesStep([ttl.end],value), Pro...                     1           1           0.127
    PropertiesStep([ttl.end],value)                                                            0.033
  TraversalFilterStep([EdgeVertexStep(IN), Prof...                                             0.144
    EdgeVertexStep(IN)                                                 1           1           0.014
    IsStep(eq([TinkerGraphStep(vertex,[d9b69296...                                             0.018
  AddEdgeStep({ttl.start=[Thu Jan 28 21:27:52 C...                     1           1           0.220
    TinkerGraphStep(vertex,[d9b69296-333e-4e54-...                     1           1           0.120

【问题讨论】:

    标签: java groovy gremlin tinkerpop3


    【解决方案1】:

    两者都应该工作:

    gremlin> g = TinkerFactory.createModern().traversal()
    ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
    gremlin> v = g.V(1).next()
    ==>v[1]
    gremlin> g.V().bothE().where(outV().is(v))
    ==>e[9][1-created->3]
    ==>e[7][1-knows->2]
    ==>e[8][1-knows->4]
    ==>e[7][1-knows->2]
    ==>e[9][1-created->3]
    ==>e[8][1-knows->4]
    gremlin> g.V().bothE().where(outV().is(eq(v)))
    ==>e[9][1-created->3]
    ==>e[7][1-knows->2]
    ==>e[8][1-knows->4]
    ==>e[7][1-knows->2]
    ==>e[9][1-created->3]
    ==>e[8][1-knows->4]
    

    请注意,您的代码示例并未显示您向is()eq() 提供Vertex。以下:

    def to = __.V(member).hasLabel('Member')
    

    永远不会得到Vertex,因为traversal is not iterated。因此to 只是一个Traversal 并且肯定不会在您的where() 中提供任何匹配项。

    【讨论】:

    • 好的,我认为我知道这是从哪里来的,但是这个解决方案在一次性遍历的约束下不起作用,我怀疑不会起作用一般在大多数供应商上;它需要首先检索V(1),然后将其用作对象值(在 TinkerGraph 中很好,但在 Neptune 中不行)。在单次遍历中说“inV 在哪里是同一个顶点”最合适的方式是什么?
    • 大多数(全部?)供应商将支持这一点。我不知道海王星不能接受Vertex。您当然可以从 Neptune 取回一个,但如果您不能发回一个,那么只需使用该 ID,不是吗? g.V().bothE().where(outV().hasId(v.id())
    • 这可能是我弄错了,但无论哪种情况,它都不是单遍历事务。我也许可以使.id() 表单工作。
    • 在我的实际代码中,coalesce 在一个方法中,to 作为参数传递(即,如果存在,则查找现有边,否则添加),并使用 to.id() 改变subtraversal,导致它在预期遍历顶点时失败。 (事后将符合泛型的Traversal<A, Vertex> 变形为Traversal<A, Object> 的能力是出乎意料的。)我已经为此打开了2515;不幸的是,这可能是需要 3.5 的更改。
    猜你喜欢
    • 2016-12-30
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多