Using BatchGraph in gremlin

242 views
Skip to first unread message

Alexandre Vallette

unread,
May 15, 2013, 10:04:37 AM5/15/13
to gremli...@googlegroups.com
hello,

I'm trying to use a batchgraph in gremlin over titan but i can't get a grip on it:
         \,,,/
         (o o)
-----oOOo-(_)-oOOo-----
gremlin>g = TitanFactory.open("config/cassandrathrift.local")
==>titangraph[cassandrathrift:127.0.0.1]
gremlin> 

gremlin> BatchGraph bg = new BatchGraph(g,VertexIDType.STRING,1000)
==>batchgraph[titangraph[cassandrathrift:127.0.0.1]]
gremlin> bg
No such property: bg for class: groovysh_evaluate
Display stack trace? [yN] 
gremlin> bg.addVertex(1)
No such property: bg for class: groovysh_evaluate
Display stack trace? [yN] 


any help appreciated.

Marko Rodriguez

unread,
May 15, 2013, 10:09:28 AM5/15/13
to gremli...@googlegroups.com
Hi,

In the Gremlin REPL, you can not define the variable type. Thus do:

bg = new BatchGraph(…)

HTH,
Marko.
--
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/groups/opt_out.
 
 

Daniel Kuppitz

unread,
May 15, 2013, 10:10:10 AM5/15/13
to gremli...@googlegroups.com
Hi Alexandre,

don't use types in Gremlin. Simply do:

gremlin> bg = new BatchGraph(g,VertexIDType.STRING,1000)

Cheers,
Daniel

Alexandre Vallette

unread,
May 15, 2013, 10:19:06 AM5/15/13
to gremli...@googlegroups.com
thanks a lot.

Is there a way to define  bg = new BatchGraph(g,VertexIDType.STRING,1000)
globally? In a configuration file or whatever so that it can be accessed as easily as g?
actually this works nice in gremlin but my initial problem was with rexpro-python where

In [19]: conn.execute("bg = new BatchGraph(g,VertexIDType.STRING,1000) ; bg.setVertexIdKey('vid'); bg.addVertex(1)")
Out[19]: {'_id': '1', '_properties': {'vid': 1}, '_type': 'vertex'}

works, but:
In [20]: conn.execute("bg = new BatchGraph(g,VertexIDType.STRING,1000) ; bg.setVertexIdKey('vid');")

In [21]: conn.execute("bg.addVertex()")
---------------------------------------------------------------------------
RexProScriptException                     Traceback (most recent call last)
<ipython-input-21-b98d150752b7> in <module>()
----> 1 conn.execute("bg.addVertex()")

/usr/local/lib/python2.7/site-packages/rexpro/connection.pyc in execute(self, script, params, isolate, transaction, pretty)
    246 
    247         if isinstance(response, messages.ErrorResponse):
--> 248             raise exceptions.RexProScriptException(response.message)
    249 
    250         return response.results

RexProScriptException: An error occurred while processing the script for language [groovy]. All transactions across all graphs in the session have been concluded with failure: java.util.concurrent.ExecutionException: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: bg for class: Script3

Daniel Kuppitz

unread,
May 15, 2013, 10:37:27 AM5/15/13
to gremli...@googlegroups.com
Is there a way to explicitly specify a session with rexpro-python? I've tried the same with my RexProClient implementation and it works just fine:

namespace ConsoleApplication3
{
    using System;
    using Rexster;

    internal class Program
    {
        private static void Main()
        {
            var client = new RexProClient("10.0.0.10");
            using (var session = client.StartSession())
            {
                client.Query("bg = new BatchGraph(g,VertexIDType.STRING,1000)", session: session);

                var v = client.Query("bg.addVertex(0)", session: session);
                if (v is Vertex && (v as Vertex).Id == "0")
                {
                    Console.WriteLine("Everything works as expected.");
                }
                else Console.WriteLine("Something went terribly wrong.");
            }
        }
    }
}

Output:

Everything works as expected.

It seems like you're using a new session for each script request.

Cheers,
Daniel

Blake Eggleston

unread,
May 15, 2013, 4:54:30 PM5/15/13
to gremli...@googlegroups.com
Hi Alexandra and Daniel,

A session is automatically opened in rexpro-python when a rexpro connection is created and is maintained for the life of the session. 

The problem you're likely having is with query isolation. By default, variables created in one request will not be available in the next. You can disable this by passing isolate=False into the execute method as a keyword argument.

If you change:
conn.execute("bg = new BatchGraph(g,VertexIDType.STRING,1000) ; bg.setVertexIdKey('vid');")
to:
conn.execute("bg = new BatchGraph(g,VertexIDType.STRING,1000) ; bg.setVertexIdKey('vid');", isolate=False)

bg will be available in all subsequent requests.

Hope that helps.

Thanks,

Blake
Reply all
Reply to author
Forward
0 new messages