How to return a filled set of vertices with properties?

401 views
Skip to first unread message

Alexandr Porunov

unread,
Mar 29, 2018, 1:42:54 PM3/29/18
to JanusGraph users
Hello,

When I traverse vertices JanusGraph returns a set of vertices that isn't filled with properties. When I use next traverse:
List<Vertex> locations = graph.traversal().V().hasLabel("location")
                    .has("location_type", 1)
                    .toList();

I am getting a big set of my locations. But for each vertex where I call value() method, it sends a request to a database to fetch properties. So basically I am getting locations.size() requests to the database:
for(Vertex locationVertex : locations){
    System.out.println("Location id: "+locationVertex.<Integer>value("location_id"));
}


Is it possible to fetch a set of vertices with filled properties in one request?

Best regards,
Alexandr

Daniel Kuppitz

unread,
Mar 29, 2018, 2:07:35 PM3/29/18
to JanusGraph users
Here are a few alternatives:

g.V().has("location","location_type",1).values("location_id")        // if you only need the location_id values
g.V().has("location","location_type",1).valueMap("location_id",...)  // if you only need a few more values, but not all
g.V().has("location","location_type",1).values("location_id")        // if you need all property values
g.V().has("location","location_type",1).values(true)                 // if you also need the vertex id

The first traversal will return a list of Integers, all others a list of maps.

Cheers,
Daniel




--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/c95794bd-8881-4ed0-9823-9d28765e48be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexandr Porunov

unread,
Mar 29, 2018, 6:47:17 PM3/29/18
to JanusGraph users
Hello Daniel,

Thanks for the advice. Is it possible to fetch vertices filled with properties? Or maybe there is a method which can get get values map and fill vertices?
I just need to get vertices from the database which are already filled with values because I use those vertices to convert them to ORM objects.

Best regards,
Alexandr


On Thursday, March 29, 2018 at 9:07:35 PM UTC+3, Daniel Kuppitz wrote:
Here are a few alternatives:

g.V().has("location","location_type",1).values("location_id")        // if you only need the location_id values
g.V().has("location","location_type",1).valueMap("location_id",...)  // if you only need a few more values, but not all
g.V().has("location","location_type",1).values("location_id")        // if you need all property values
g.V().has("location","location_type",1).values(true)                 // if you also need the vertex id

The first traversal will return a list of Integers, all others a list of maps.

Cheers,
Daniel



On Thu, Mar 29, 2018 at 10:42 AM, Alexandr Porunov <alexandr...@gmail.com> wrote:
Hello,

When I traverse vertices JanusGraph returns a set of vertices that isn't filled with properties. When I use next traverse:
List<Vertex> locations = graph.traversal().V().hasLabel("location")
                    .has("location_type", 1)
                    .toList();

I am getting a big set of my locations. But for each vertex where I call value() method, it sends a request to a database to fetch properties. So basically I am getting locations.size() requests to the database:
for(Vertex locationVertex : locations){
    System.out.println("Location id: "+locationVertex.<Integer>value("location_id"));
}


Is it possible to fetch a set of vertices with filled properties in one request?

Best regards,
Alexandr

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-use...@googlegroups.com.

Daniel Kuppitz

unread,
Mar 30, 2018, 10:02:57 AM3/30/18
to JanusGraph users
The fastest way in Titan was a MultiQuery, if I remember correctly, but it seems like it's deprecated in JanusGraph: https://static.javadoc.io/org.janusgraph/janusgraph-core/0.1.1/org/janusgraph/core/JanusGraphMultiVertexQuery.html
Thus I'm not really sure what the recommendation is for JanusGraph.

Cheers,
Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/0a990def-fb64-4ad2-9c17-862013170239%40googlegroups.com.

Alexandr Porunov

unread,
Mar 30, 2018, 1:01:09 PM3/30/18
to JanusGraph users
Daniel,

You are a life saver! Thank you very much for the help!
I don't know why it is deprecated in JanusGraph but it really works like I need.
Here is what I did:

List<Vertex> locations = graph.traversal().V().hasLabel("location").has("location_type", 3).next(50000);
graph.multiQuery().addAllVertices(locations).properties();
Integer myId = locations.get(123).<Integer>value("location_id"); // Properties are returned immediately without network calls.

Thank you very much again.

Best regards,
Alexandr

Misha Brukman

unread,
Mar 31, 2018, 10:22:28 PM3/31/18
to Daniel Kuppitz, JanusGraph users
Hi Daniel,

I see @Deprecated markers in StandardJanusGraphTx#multiQuery(), however, those were added in April 2015, which means it was added to Titan, and were simply brought over to JanusGraph.

What would you suggest we should do here?

Misha

Daniel Kuppitz

unread,
Mar 31, 2018, 10:59:16 PM3/31/18
to Misha Brukman, JanusGraph users
I don't know or don't remember what the plan was, but if the Janus devs think it's a good implementation, then just un-deprecate it..? :)

Cheers,
Daniel

HadoopMarc

unread,
Apr 2, 2018, 10:00:04 AM4/2/18
to JanusGraph users
Hi Misha,

As remarked earlier here, my guess is that the MultiQuery API is deprecated because of replacement by:

https://static.javadoc.io/org.janusgraph/janusgraph-core/0.2.0/org/janusgraph/graphdb/query/vertex/MultiVertexCentricQueryBuilder.html

It would be useful, though, to have:
 - a section in the JanusGraph ref docs about the MultiVertexCentricQuery
 - some pointers in the deprecated API towards the new one

Cheers,    Marc

Op zondag 1 april 2018 04:59:16 UTC+2 schreef Daniel Kuppitz:

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-use...@googlegroups.com.

Misha Brukman

unread,
Apr 2, 2018, 10:16:04 AM4/2/18
to HadoopMarc, JanusGraph users
Thanks, Marc! I filed https://github.com/JanusGraph/janusgraph/issues/984 to track this task.

To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/a1c9c5b9-04f9-464f-bc06-acb1438fe44a%40googlegroups.com.

chris....@gmail.com

unread,
Apr 5, 2018, 5:47:47 PM4/5/18
to JanusGraph users
I started to write up the fix for this and I don't think MultiVertexCentricQueryBuilder is replacement method since JanusGraphMultiVertexQuery is dependent on it and it came out in early 2014. 

lines 1031-1045 of janusgraph-core/src/main/java/org/janusgraph/graphdb/transaction/StandardJanusGraphTx.java
    @Override
    @Deprecated
    public JanusGraphMultiVertexQuery multiQuery(JanusGraphVertex... vertices) {
        MultiVertexCentricQueryBuilder builder = new MultiVertexCentricQueryBuilder(this);
        for (JanusGraphVertex v : vertices) builder.addVertex(v);
        return builder;
    }

    @Override
    @Deprecated
    public JanusGraphMultiVertexQuery multiQuery(Collection<JanusGraphVertex> vertices) {
        MultiVertexCentricQueryBuilder builder = new MultiVertexCentricQueryBuilder(this);
        builder.addAllVertices(vertices);
        return builder;
    }

I spent about an hour digging and found a vague reference that the replacement should be available in titan 1.0 https://github.com/thinkaurelius/titan/issues/1037, but I couldn't fine anything in the titan PRs or gremlin change notes. If there's no existing replacement and no current plans implement a replacement would it make sense to just un-deprecate it? aka +1 to Daniel's post.

Ted Wilmes

unread,
Apr 29, 2018, 9:43:25 AM4/29/18
to JanusGraph users
I added my two cents on this topic up at https://github.com/JanusGraph/janusgraph/issues/984. I'm in agreement that it should be un-deprecated.

--Ted
Reply all
Reply to author
Forward
0 new messages