0
.choose(values('points')
  .option(lt(500), updating the vertex properties)
  .option(gt(500), updating and creating new properties)
  .option(none,creating new vertex )) 

points is vertex property of type integer

I want to perform less than and greater than operations inside option. I am trying in the above way.Please correct me if I am wrong.

If there is any other way to perform this please let me know.

Thank you

Namani Supriya
  • 41
  • 1
  • 14

1 Answers1

2

This feature hasn't been implemented as of Apache TinkerPop 3.4.2. It is a long standing open issue: TINKERPOP-1084. I think that if you want this functionality, you're going to have do a nested choose():

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().hasLabel('person').
......1>   choose(values('age').is(lt(29)),
......2>          constant('lt29'),
......3>          choose(values('age').is(gt(29)),
......4>                 constant('gt29'),
......5>                 constant('29')))
==>29
==>lt29
==>gt29
==>gt29

Note that you aren't restricted to constant() as a result of these nested choose() operations. You can add any anonymous traversal you like there as in:

gremlin> g.V().hasLabel('person').
......1>   choose(values('age').is(lt(29)),
......2>          constant('lt29'),
......3>          choose(values('age').is(gt(29)),
......4>                 math('_ - 29').by('age'),
......5>                 constant('29')))
==>29
==>lt29
==>3.0
==>6.0
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • If the values of age is **gt29** then I want to **subtract** 29 from age.I think to achieve this I have to store the value of age inside the query.Is it possible to store the values inside query.If possible,how can I store the values.Otherwise how can I achieve this. . Thank you – Namani Supriya Jun 12 '19 at 07:24
  • you can just use `math()` step – stephen mallette Jun 12 '19 at 11:23
  • Thanks for answering Mr.Stephen.Subtraction can be done through math step.But in my case I am referring to points.Let us take an example **vertex as AddPts** containing **totalPoints** as property.After adding specific(ex:20) points to the property it should not exceed 500.If it is going to exceed 500.Then I need to add those extra points by adding new vertex.For this I need get the current vertex property **totalPoints** value and subtract the value from 500. Can you give a example for this. – Namani Supriya Jun 13 '19 at 06:55
  • Well, you know you have `math()` step to do calculations. Why not just change line 1 to `choose(values('totalPoints').math('_+20').is(lt(500))` then you don't actually modify the property value until you know if it exceeds your limit. if you need a working example, i suggest that you write a new question with some sample data like https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random – stephen mallette Jun 13 '19 at 10:51
  • Thank you Mr.Stephen.I wrote new question with sample data.Can you please check it here https://stackoverflow.com/questions/56580992/gremlin-adding-new-vertex-if-it-exceeds-the-limit]. – Namani Supriya Jun 13 '19 at 13:09