Gremlin Query builder

477 views
Skip to first unread message

Senthil Jayakumar

unread,
Jul 14, 2015, 4:14:01 PM7/14/15
to gremli...@googlegroups.com
Hi There,

I'm implementing utility method which will build the query based on the input,

for e.g. the following queries were constructed

query 1:
String query = .as('x').out().out().out().out().has("objectType","com.networks.osa.dao.domain.Cloud").has("name","blr-cloud").back('x').out().out().out().out().has("objectType","com.networks.osa.dao.domain.VirtualCPUCount").property("count")

query 2:
String query = .out().out().out().out().has("objectType","com.networks.osa.dao.domain.VirtualCPUCount").property("count")

Based on the condition specified below, I need to append one of the above mentioned query with the pipe.

            if(id.equals("ServiceOrder"))
            {
                pipe = new GremlinPipeline<Vertex, Vertex>(graph.getVertices());
            }
            else
            {
                Vertex v = graph.getVertex(Long.parseLong(id));
                pipe = new GremlinPipeline<Vertex, Vertex>(v);
            }

finally, the complete query should look like, "pipe + query" and access any other method like .toList() etc. Is there a way to construct the query separately and use them like by passing the query as input to any existing method or by appending the query to pipe?

List<Object> counts = pipe + query.toList();

Appreciate your help in this regard.

Thanks,
Senthil Jayakumar






Senthil Jayakumar

unread,
Jul 21, 2015, 4:43:27 AM7/21/15
to gremli...@googlegroups.com
Any help in this regard is very much appreciated. 

Stephen Mallette

unread,
Jul 21, 2015, 5:52:23 AM7/21/15
to gremli...@googlegroups.com
So, you construct the queries as String values and you want to append that to a different way of starting the traversal?  Why not just construct the start of the query as a String as well?  

String queryEnd = ".out().out().out().out().has("objectType","com.networks.osa.dao.domain.VirtualCPUCount").property("count")"
String query;
if(id.equals("ServiceOrder"))
{
    query = "g.V" + queryEnd
}
else
{
    query = "g.v(1)"  + queryEnd
}

That seems really simple so I must be missing some aspect of your question.


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/f3d54354-f0da-4fc8-b9f3-3f33ab5e0583%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Daniel Kuppitz

unread,
Jul 21, 2015, 2:01:47 PM7/21/15
to gremli...@googlegroups.com
Maybe the question is about pipe concatenation..?

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.V().out()
==>v[3]
==>v[2]
==>v[4]
==>v[3]
==>v[5]
==>v[3]
gremlin> pipeEnd = _().out(); []
gremlin> pipeStart = g.V(); []
gremlin> pipe = pipeStart.add(pipeEnd); []
gremlin> pipe.toString()
==>[GremlinStartPipe, GraphQueryPipe(vertex), [GremlinStartPipe, VertexQueryPipe(out,[],vertex)]]
gremlin> pipe
==>v[3]
==>v[2]
==>v[4]
==>v[3]
==>v[5]
==>v[3]
gremlin>

Not sure if there was a better way in TP2.

Cheers,
Daniel


Reply all
Reply to author
Forward
0 new messages