Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of improved option() capability. #173

Closed
krlawrence opened this issue Mar 9, 2020 · 1 comment
Closed

Add example of improved option() capability. #173

krlawrence opened this issue Mar 9, 2020 · 1 comment

Comments

@krlawrence
Copy link
Owner

krlawrence commented Mar 9, 2020

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

@krlawrence
Copy link
Owner Author

Closing as this is fixed and work has now started on the second edition. There will likely be one final release of the v283 first edition line before the V2 branch becomes the second edition. That release will include these fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant