Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a empty array inside a Gremlin traversal?

This sounds silly but is there a way to create a empty array inside a Gremlin traversal?

For the query below:

g.V().has('person','name', 'marko').project('a', 'b').by().by()

I want to project b as an empty array. I have tried:

g.V().has('person','name', 'marko').project('a', 'b').by().by(constant("").fold())

But constant("").fold() is not actually empty constant("").fold().count() returns 1. This applies to constant(null).fold() as well.

like image 957
Glide Avatar asked Jan 02 '23 15:01

Glide


2 Answers

Is this what you are looking for

g.withSideEffect('x',[]).V().has('person','name','marko').project('a','b').by(select('x')).by('name')

==>[a:[],b:marko]
like image 75
Kelvin Lawrence Avatar answered Jan 12 '23 18:01

Kelvin Lawrence


An empty array/collection would actually be a fold() of nothing. You'll get nothing if you filter everything, hence:

g.V().has('person','name','marko').
  project('a', 'b').
    by().
    by(__.not(identity()).fold())
like image 24
Daniel Kuppitz Avatar answered Jan 12 '23 16:01

Daniel Kuppitz