0
votes

I am using janus graph deployed in embedded mode. And i am using java. And firing following queries

--> g.V().has('deleted',false).valueMap() //slow

--> g.V().has('deleted',false).toList() //slow

the above query takes time after implementing composite indexes also

--> g.V().has('deleted',false) //fast

above query is fast and use implemented composite index created on deleted key.

Also tried the same using java code

        List<Vertex> list = new ArrayList<>();

        DateTime dt1 = new DateTime();
        JanusGraphQuery<? extends JanusGraphQuery> query = GraphClient.getJGraph().query();
        Iterator iterator = query.has("deleted",false).vertices().iterator();
        while(iterator.hasNext()) {
            Vertex next = (Vertex) iterator.next();
            getPropertyMapByVertex(next); //time consuming to convert vertex into Map.
            list.add(next);
        }


     public static Map<String, Object> getPropertyMapByVertex(Vertex vertex) {
    Map<String, Object> propertyMap = new HashMap<>();
    try {
        if (vertex != null) {
            Iterator<VertexProperty<Object>> properties = vertex.properties();
            if (properties != null) {
                while (properties.hasNext()) {
                    Property<Object> property = properties.next();
                    propertyMap.put(property.key(), property.value());
                }
                propertyMap.put(GraphConstants.VERTEX_ID, vertex.id());
            }
        }
    } catch (Exception e) {
        logger.error("Exception in getPropertyMapByVertex : {}", ExceptionUtils.getStackTrace(e));
    }
    return propertyMap;
}

do we have some way to fast "getPropertyMapByVertex" method or any other way to fire query and get data quickly using java.

1

1 Answers

2
votes

I haven't been following the development progress in JanusGraph, but if the multiQuery API is still available, you should give it a try:

List<Vertex> vertices = g.V().has('deleted',false).toList();
graph.multiQuery().addAllVertices(vertices).properties();

That's untested code written from memory, ultimately it may look a bit different.

However, since you mention that g.V().has('deleted',false).toList() is slow, but g.V().has('deleted',false) is fast, I'm not sure if you really understand what's going on. The latter statement by itself does absolutely nothing, while the former statement actually fetches all the vertices.