none
.Tail() does not seem to be working in Gremlin API RRS feed

  • Question

  • **To Reproduce**

    Create an empty graph partitioned on 'a' and seed with the following:

    ```
    g.addV('person').property('a','1').property('name','person 1').property('number',1)
    g.addV('person').property('a','1').property('name','person 2').property('number',2)
    g.addV('person').property('a','1').property('name','person 3').property('number',3)

    g.V().order().by('number')
    returns: person 1, person 2, person 3

    g.V().order().by('number').tail(1)
    returns: person 1

    ```

    I expected .tail() to return from the end of the list
    Whats weird is that when i select just a property it works just as I expected:

    ```
    g.V().order().by('number').properties('name')
    returns: person 1, person 2, person 3

    g.V().order().by('number').properties('name').tail(1)
    returns: person 3
    ```

    I have also managed to get it to work on vertices by doing a .fold().unfold() before .tail()

    In the tinkerpop gremlin console behavior is that .tail() always start from the end.

    Wednesday, November 20, 2019 8:02 AM

Answers

  • Hi 

    PG team has identified the issue on their end and they are incorrectly treating tail() the same as limit() during query optimization.

    They have created a work item on their end to resolve it but there is no ETA attached to the same. It will be few weeks before the hot fix is deployed but they have provided the workaround to use for this scenario in the meantime.

    You can re-write a query of this form:

    g.V().order().by('number').tail(n)

    Into an equivalent query that uses limit() instead of tail():

    g.V().order().by('number', decr).limit(n).order().by(‘number’)

    Please note the key changes here:

    1. The initial order().by() sort direction is reversed so that the desired items will appear at the beginning of the result set.
    2. The tail() step is switched to limit() so that we definitely take items from the beginning of the result set.
    3. A second order().by() is performed on the n results produced by the limit() step to correct the reversed sort order.

    This is just a short time mitigation for your scenario. But the journey to correct this permanently has started and will be deployed in next release.

    Hope this helps.

    Thanks
    Navtej S

    Wednesday, November 20, 2019 10:18 PM
    Moderator

All replies

  • Hi Kenewbie

    We are checking this with our PG team and we will get back to you as soon as possible.

    Thanks
    Navtej S


    Wednesday, November 20, 2019 3:27 PM
    Moderator
  • Hi 

    PG team has identified the issue on their end and they are incorrectly treating tail() the same as limit() during query optimization.

    They have created a work item on their end to resolve it but there is no ETA attached to the same. It will be few weeks before the hot fix is deployed but they have provided the workaround to use for this scenario in the meantime.

    You can re-write a query of this form:

    g.V().order().by('number').tail(n)

    Into an equivalent query that uses limit() instead of tail():

    g.V().order().by('number', decr).limit(n).order().by(‘number’)

    Please note the key changes here:

    1. The initial order().by() sort direction is reversed so that the desired items will appear at the beginning of the result set.
    2. The tail() step is switched to limit() so that we definitely take items from the beginning of the result set.
    3. A second order().by() is performed on the n results produced by the limit() step to correct the reversed sort order.

    This is just a short time mitigation for your scenario. But the journey to correct this permanently has started and will be deployed in next release.

    Hope this helps.

    Thanks
    Navtej S

    Wednesday, November 20, 2019 10:18 PM
    Moderator
  • Thank you for the quick reply.

    I am using both limit() and tail() in the same query but I'll see if I am able to rewrite it similar to your proposal without anything breaking. Where can I keep up to date on new releases?

    Thursday, November 21, 2019 7:35 AM
  • Hi 

    For this item PG team has created the work item and can provide the updates about the same here:

    https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/39141565-tail-gremlin-step-support

    PG team need the information about you and your work, your use case and timeline to fully understand how to address this item.

    You can send the mail to AzCommunity for giving this information. Get back to me for any questions.

    Thanks
    Navtej Singh Saini

    Wednesday, November 27, 2019 4:18 PM
    Moderator