graph icon indicating copy to clipboard operation
graph copied to clipboard

Add an example of using coalesce() inside a by() modulator.

Open krlawrence opened this issue 5 years ago • 1 comments

Should add an example that shows that this is possible

gremlin> g.V(0,3).project('city').by(coalesce(values('city'),constant('not found')))
==>[city:not found]
==>[city:Austin]

krlawrence avatar Mar 09 '20 23:03 krlawrence

I have another usage for coalesce that will be useful for 'upsert', in python:

   airport_code = 'HLO'
   airport_description = 'World'

    t = (g.V()
         .has('airport', 'code', airport_code)
         .fold()       # "None" is folded if not found
         .coalesce(
            unfold(),  # if "None" is unfolded the 'else' part of coalesce step is taken
            g.addV('airport')
            .property('code', airport_code)
         )
         .property('description', airport_description)
    # ...
    )

    assert next(t, None)

Pippin555 avatar Apr 06 '21 20:04 Pippin555

As part of the changes to address this issue, we should also discuss the changes to the way "non productive" by modulators now act as filters in Gremlin post 3.6.0.

krlawrence avatar Sep 23 '23 18:09 krlawrence