Search code examples
gremlintinkerpopamazon-neptune

What is the gremlin query for sorting by putting empty values at the bottom


I am trying to find an equivalent for the below SQL query in the Gremlin query.

select * from test.test_table order by alias = '', alias asc, name asc;

The above query does the sorting based on ascending order by putting empty rows at the bottom. enter image description here

In the Gremlin query, I am trying to write the below query but alias property with empty values are coming at the top.

I want to have proper sorting for the alias field but empty and null values should go at the bottom.

g.V("ID").inE('RELATIONSHIP_NAME').outV().order().by('alias', asc).by('name', asc).valueMap().toList()

Thank you.


Solution

  • I somehow found the correct answer which is working.

    g.V("ID").
      inE('RELATIONSHIP').
      outV().
      order().
        by(choose(values('alias').is(''),constant(1), constant(0)), asc).
        by('alias', asc).by('name', asc).range(0,-1).valueMap()