0

I want to perform dynamic ordering on a field through the gremlin query, I am using following query

g.inject('asc').as('mode').
V().
choose(select('mode').is('asc'), 
        order().by('lastName'), 
        order().by('lastName', decr)).
values('lastName')

This seems to work fine, but using inject is degrading the performance of the query.

Is there an alternative way of achieving the same functionality in Cosmos DB Gremlin API?

  • how much faster is `g.V().order().by('lastName').values('lastName')` compared to what you are using? – stephen mallette Jun 17 '20 at 10:38
  • g.V().order().by('lastName') works much faster but I want to pass the sorting order incr or decr, dynamically, which is not possible in this query, hence, I need to use inject – Kajal Patel Jun 18 '20 at 05:29
  • I found a solution, g.V().choose(constant(*SortOrder*).is('incr'), order().by('lastName', incr), order().by('lastName', decr)), here I can pass sort order dynamically. – Kajal Patel Jun 18 '20 at 05:30
  • 1
    why do you have to pass the `Order` as a `String` value at all? why not just define your parameter as: `g.V().order().by('lastName', param)` and then just pass `Order.asc` or `Order.desc` for that "param"? – stephen mallette Jun 18 '20 at 11:55
  • @stephenmallette that was the first thing I tried, but it was not working – Kajal Patel Jun 18 '20 at 12:57
  • 1
    what does "not working" mean? an error? i don't think there is a reason it should not work - at least from Gremlin's perspective. – stephen mallette Jun 18 '20 at 13:14
  • 1
    @stephenmallette there are 2 parameters, order().by(_SortColumn_, _SortOrder_), here SortColumn works fine, but when trying to pass the sort order, incr or decr as paramaeter, it throws an error. – Kajal Patel Jun 18 '20 at 14:44
  • what is the error? – stephen mallette Jun 18 '20 at 14:56

0 Answers0