Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
63 views
in Technique[技术] by (71.8m points)

java - Can Gremlin P.eq accept a Vertex?

I'm trying to apply the Element Existence recipe to insert only one edge that's considered "live" (not "expired"):

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()

My expectation is that the coalesce will select an existing edge that has no ttl.end property and is incident onto the same to vertex, or else insert a new edge. However, a new edge is always inserted anyway. I interpret this as indicating that the first subtraversal isn't matching the existing live edge, but I'm not figuring out why. Does the predicate P.eq work for a Traversal<?, Vertex> argument? If not, what's the correct way to say "where the edge ends on vertex to"?

Profile (I note the IsStep has no traversers, which I interpret to mean it did not match):

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
question from:https://stackoverflow.com/questions/65948295/can-gremlin-p-eq-accept-a-vertex

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Either should work:

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]

Note that your code example doesn't show you providing a Vertex to is() or eq(). The following:

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

never gets the Vertex because the traversal is not iterated. Therefore to is just a Traversal and that certainly won't provide any matches in your where().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...