Skip to content

Add example of improved option() capability. #173

@krlawrence

Description

@krlawrence

Release 3.4.3 added the ability for option steps used with a choose step to include traversals so constructs like the one below are now possible.

g.V().hasLabel('airport').
      groupCount().
        by(__.choose(__.values('elev')).
                     option(gt(5000),__.constant('high')).
                     option(gt(3000),__.constant('medium')).
                     option(Pick.none,__.constant('low'))) 

Also show to do it before would have taken something like

res = ( g.V().hasLabel('airport').
              groupCount().
                by(__.choose(__.values('elev').is_(gt(5000)),
                             __.constant('high'),
                             __.choose(__.values('elev').is_(gt(3000)),
                                       __.constant('medium'),
                                       __.constant('low')))).
              order(Scope.local).by(Column.values).
              next() )

As part of this also document the Pick enum.
org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent.Pick

Maybe also show something like this as the old option usage

gremlin> g.V().hasLabel('airport').
......1>       has('region','US-TX').fold().
......2>       choose(count(local)).
......3>         option(1,constant('one')).
......4>         option(0,constant('none')).
......5>         option(none,constant('neither one or zero'))
==>neither one or zero
gremlin> g.V().hasLabel('airport').
......1>       has('code','AUS').fold().
......2>       choose(count(local)).
......3>         option(1,constant('one')).
......4>         option(0,constant('none')).
......5>         option(none,constant('neither one or zero'))
==>one
gremlin> g.V().hasLabel('airport').
......1>       has('code','XYZ').fold().
......2>       choose(count(local)).
......3>         option(1,constant('one')).
......4>         option(0,constant('none')).
......5>         option(none,constant('neither one or zero'))
==>none       

As part of this update the Pick enum needs to be added to the list of enum tables

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions