Subgraphs using sideEffects Gremlin-OrientDb-Java

212 views
Skip to first unread message

Sabari Gandhi

unread,
Apr 9, 2014, 5:06:02 PM4/9/14
to gremli...@googlegroups.com
Use case: Get a sub graph of person by city lookup (with all associated edges and the vertices) in one query in Java.

When I used GremlinPipe:

    GremlinPipeline startPipe  =  pipe.has("city-name", "NY").inE("city-depends").outV();


Using this I get the result but to get additional inof i need to make further calls
:  [v(Person)[#15:13], v(Person)[#15:7], v(Person)[#15:12], v(Person)[#15:11], v(Person)[#15:10], v(Person)[#15:9], v(Person)[#15:8]]

I used sideEffect and did the following but still get the same result (person info) and not the graph.

    List list = pipe.has("city-name", "NY").inE("city-depends").outV().sideEffect(new PipeFunction<Vertex, Vertex>() {
        public Vertex compute(Vertex it) { 
            temp.add(it.getEdges(Direction.IN, "friends"));
            return it; 
        } 
    }).toList();

Using this I get List<edge> with friends information. Do i need to again create a list add  edges like this if i need to traverse another edge for example owns which is also from person ?

I read and used "traverse" in orientdb sql which provides the graph. Is there any gremlin equivalent or any other efficient way to get the sub graph. 

Any help is greatly appreciated. Thanks !!

Daniel Kuppitz

unread,
Apr 9, 2014, 6:58:32 PM4/9/14
to gremli...@googlegroups.com
Try this:

pipe.has("city-name", "NY").in("city-depends").transform({
    [it, it.in("friends").toList()]
}).toList()

The conversion from Groovy to Java is your job. Good luck :)

Cheers,
Daniel




--
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.
For more options, visit https://groups.google.com/d/optout.

Sabari Gandhi

unread,
Apr 15, 2014, 2:15:54 PM4/15/14
to gremli...@googlegroups.com
Daniel: Thanks for the response.

 I am using Groovy gremlin in my Java class to traverse orient-db and see the below issue. If I use :

    g.V('@class','Person').has('city-name','NY').in('city-depends').toList()

I get the persons based on the city and If i try using transform to also get the friends of person using the edge friends

    g.V('@class','Person').has('city-name','NY').in('city-  depends').transform({[it,it.in('friends').toList()]}).toList()

What I want is information of persons based in the city WITH their friends information (not only the edge id)

I get the following error 

com.orientechnologies.orient.core.exception.OStorageException: Error on executing command: 

at com.orientechnologies.orient.client.remote.OStorageRemote.handleException(OStorageRemote.java:1481)

at com.orientechnologies.orient.client.remote.OStorageRemote.command(OStorageRemote.java:1059)

at com.orientechnologies.orient.client.remote.OStorageRemoteThread.command(OStorageRemoteThread.java:430)

at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:59)

at orientdb.prototype.OrientGremlinExample.getActivityByResource(OrientGremlinExample.java:87)

at orientdb.prototype.OrientGremlinExample.main(OrientGremlinExample.java:26)

Caused by: java.lang.IllegalArgumentException: Unsupported record type: 0

at com.orientechnologies.orient.core.record.ORecordFactoryManager.newInstance(ORecordFactoryManager.java:93)

at com.orientechnologies.orient.enterprise.channel.binary.OChannelBinaryProtocol.readIdentifiable(OChannelBinaryProtocol.java:121)

at com.orientechnologies.orient.client.remote.OStorageRemote.command(OStorageRemote.java:1023)

... 4 more

Caused by: java.lang.IllegalArgumentException: Record type '0' is not supported

at com.orientechnologies.orient.core.record.ORecordFactoryManager.getFactory(ORecordFactoryManager.java:108)

at com.orientechnologies.orient.core.record.ORecordFactoryManager.newInstance(ORecordFactoryManager.java:91)

... 6 more


My complete java code for the reference
 
    OGremlinHelper.global().create();

    ScriptEngine engine = new GremlinGroovyScriptEngineFactory().getScriptEngine();

    engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", graph);
 
    OCommandGremlin command = new OCommandGremlin(" ...... ");

    Map<String, Object> params = new HashMap<String, Object>();

    List agg1 = graph.getRawGraph().command(command).execute(params);

    System.out.println("Result:-- " + agg1);

Any help is greatly appreciated.

Thanks,
Sabari

Luca Garulli

unread,
Apr 16, 2014, 12:39:36 AM4/16/14
to gremlin-users
Hi,
I suggest you to use OrientDB 1.7-SNAPSHOT where we fixed an issue like this.

Lvc@

Sabari Gandhi

unread,
Apr 16, 2014, 9:38:46 AM4/16/14
to gremli...@googlegroups.com
Hi Lucas: Thanks for the response. I an using 1.7 rc2 version of orient libraries and gremlin-java -2.5.0-SNAPSHOT.Please see below my complete maven dependencies. Thanks !!

com.tinkerpop.gremlin - gremlin-java -2.5.0-SNAPSHOT
com.orientechnologies-orient-commons-1.7-rc2
com.orientechnologies-orientdb-core-1.7-rc2
com.orientechnologies-orientdb-graphdb-1.7-rc2
com.orientechnologies-orientdb-client-1.7-rc2
com.orientechnologies-orientdb-object-1.7-rc2
com.orientechnologies-orientdb-enterprise-1.7-rc2

Thanks,
Sabari
Reply all
Reply to author
Forward
0 new messages