niklaus
niklaus

Reputation: 334

Use Gremlin with Java API for OrientDB

I'm using Gremlin to traverse OrientDB, but I'm not quite understand the demo code from here OrientDB Gremlin Wiki
Here is my code, what's wrong with this code?

            // create sample node and edge
        graph = new OrientGraph("local:C:/temp/graph/db");
        Vertex v1 = graph.addVertex(null);
        v1.setProperty("name", "A");
        Vertex v2 = graph.addVertex(null);
        v2.setProperty("name", "B");
        Vertex v3 = graph.addVertex(null);
        v3.setProperty("name", "C");
        graph.addEdge(null, v1, v2, "KNOWS");
        graph.addEdge(null, v1, v3, "KNOWS");

        OGremlinHelper.global().create();
        OCommandGremlin command = new OCommandGremlin("g.v('#8:0').out('KNOWS').aggregate(x).has('name',name)");
        Map<String, Object> params = new HashMap<String, Object>();
        List agg = new ArrayList();
        params.put("x", agg);
        params.put("name", "B");            
        Vertex vertex = graph.getRawGraph().command(command).execute(params);
        System.out.println(vertex);
        System.out.println(agg);

I can get the final result of the script, but why can't I get the "aggregate" result? How can I get it?

I'm really new to it. Thanks in advance!

Upvotes: 4

Views: 3184

Answers (1)

niklaus
niklaus

Reputation: 334

https://github.com/nuvolabase/orientdb/wiki/Gremlin Here said that output can only be declared with parameters passed to ScriptEngine, and the output must be an HashMap. Hope OrientDB team will enhance this at the next version.

Upvotes: 1

Related Questions