Search code examples
javagremlinjanusgraph

How to write gremlin jannusgraph predicate lt, lte, gte etc in java?


I am developing java backend over janusgraph database.

I need to write the below gremlin query in Java. I know there is a Compare Enum in janusgraph that contains lt, lte ,eq ... but the test function takes two params so I need to know how it is writen in java.

Gremlin syntax:

 g.V().hasLabel("person").has("age", lte(29))

In Janusgraph I guess !:

  g.V().hasLabel("person").has("age", Compare.lte.test({{XXX}},29))

Where {{XXX}} should be replaced by the queried item.

Thanks


Solution

  • I'm not sure I follow your question as your first query is Java:

    g.V().hasLabel("person").has("age", lte(29))
    

    As long as you static import P.lte with:

    import static org.apache.tinkerpop.gremlin.process.traversal.P.lte;
    

    you can write the traversal that way and it will work just fine. If you don't static import that method then you have to do:

    g.V().hasLabel("person").has("age", P.lte(29))
    

    Either way you need to import some aspect of P.