Can vertex properties stored as integers be incremented and decremented? If so, how?
For a fixed dataset, does coalesce() always return the same item? Is it possible to randomise it or any other way to do it? For instance of all the incoming vertices, choose a random one every time even if the dataset itself is not changed.
相关问题
- Is there a document about how gremlin 'match()
- Gremlin Python in Web Application
- How to connect Gremlin Server to a remote Neo4j Da
- Limit number of items in group().by() in gremlin q
- Merging maps in Gremlin
相关文章
- How to add vertices to gremlin server in a batch f
- How to use ElasticSearch index in Titan Gremlin qu
- Gremlin remote command fails with timeout error: H
- How do I connect to a remote Neo4j database using
- How to delete graph in Titan with Cassandra storag
- Unable to create a composite index, stuck at INSTA
- Can RDF model a labeled property graph with edge p
- Getting vertices that are connected to ALL current
You can use
sack()
:Let's look at the traversal more closely now that you've seen it in action above:
So for each vertex, you place a value in its "sack" with
assign
- theby('counter')
modulator defines that assignment as the value of the "counter" property (which was initialized to zero earlier in my example). Then withsack(sum)
we define how we increment the counterby(constant(1))
or "by 1" (i.e. take the value in the sack and sum it together with 1 and store that value in the sack). Finally we take the value out of the sack and overwrite the original "counter" property with the new value withproperty('counter', sack())
.Most questions that pertains to "element order" must be deferred to the underlying graph system. If your graph database returns elements in a deterministic order then your Gremlin should. If you need to be sure of an order and have a completely portable query then you should include use of
order()
step in Gremlin.I believe that coalesce will always go with the first traversal to return a value, so in:
you will always get the result of
outE()
if the current vertex has outgoing edges. To get a random choice out maybe you could do something like:That kinda works...in other words, for cases where
outE()
returns something, 50% of the time it would return nothing and thus allow theinE()
option to work. I'm not sure exactly what you're after but perhaps you can getcoalesce()
out of the equation and just use simplecoin()
,sample()
, etc to solve your problem.