How to rewrite OrientDB query to Gremlin (TinkerPop)?

36 Views Asked by At

I have simple OrientDB query

MATCH {class:SomeObj, as:obj, 
Where:(
        (outE('SomeEdge')[in=#74:2].StringValue="STRINNNGGG") and
        (outE('SomeEdge')[in=#75:2].NumberValue=333)
    )
}
RETURN obj

The query returns one record in OrientDB Studio.

I am trying to execute the query in JAVA using Gremlin, but I did not succeed. I tried to execute these queries:

This query results in NoSuchElementException:

g.V().hasLabel("SomeObj").as("obj")
                .where(
                        __.outE("'SomeEdge").inV().hasId("#74:2").has("StringValue", P.eq("STRINNNGGG"))
                        .and()
                        .outE("'SomeEdge").inV().hasId("#75:2").has("NumberValue", P.eq(333))
                )
                .select("obj")
                .next();

The next query results in a ClassCastException in constructor of new AndP(), because str and number are not predicates.

        GraphTraversal<Vertex, Vertex> str = __.outE("'SomeEdge").inV().hasId("#74:2").has("StringValue", P.eq("STRINNNGGG"));
        GraphTraversal<Vertex, Vertex> number = __.outE("'SomeEdge").inV().hasId("#75:2").has("NumberValue", P.eq(333));
    
        AndP andPredicate = new AndP(List.of(str, number));

        g.V().hasLabel("SomeObject").as("obj")
                .where(andP)
                .select("obj").next();

How to rewrite above OrientDB query to Gremlin?

Also, I would like to see query which is built by Gremlin, but i didn't find a way

  1. To log all queries which is executed on OrientDB server Community Edition (analog log_statement=ALL in data/postgresql.conf of Postgres)
  2. To log all queries on gremlin-server
  3. To print built query in java API, like example g.V().hasLabel("SomeObject").toString() -> select from SomeObject

I would appreciate it if you could tell me how to print query.

1

There are 1 best solutions below

0
yasuro On

I figured out:

g.V().hasLabel("SomeEdge").as("obj")
               .where(
                      and(
                          outE("SomeEdge").and(where(inV().hasId("#74:2")),values("StringValue").is(P.eq("STRINNNGGG"))),
                          outE("SomeEdge").and(where(inV().hasId("#75:2")),values("NumberValue").is(P.eq(333)))
                      )
               )
               .select("obj");

Hope it will help to someone.

But I didn't find out how to enable query logs on Orient or Gremlin server yet.