user defined steps

35 views
Skip to first unread message

Nikhanj

unread,
Oct 11, 2012, 8:14:31 AM10/11/12
to ne...@googlegroups.com
Hi 
    How to have an user defined step, returning a map.
   I tried the below code

   Gremlin.defineStep('fn1',[Vertex,Pipe],
   {
reltype,m->_().out(reltype).Name.groupCount(m).iterate();
   });
    
    m=[:];
    g.v(2).fn1('Likes',m);

    But i get class cast exception!!!

    How to resolve this ???

Stephen Mallette

unread,
Oct 11, 2012, 9:19:51 AM10/11/12
to ne...@googlegroups.com
You are calling iterate() after groupCount and that is causing that
error. Removing it and simply accessing m after the gremlin has
executed will allow you to get at the count.

If you explicitly want to return the value of the groupCount to the
next step, I guess you could define your step this way:

Gremlin.defineStep('fn', [Vertex, Pipe], { x ->
_().out(x).name.groupCount.cap})

and then do:

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> \. test.grm
==>null
gremlin> m = g.v(1).fn('created').next()
==>lop=1
gremlin> m
==>lop=1

Does that help?

Stephen
> --
>
>

Nikhanj

unread,
Oct 22, 2012, 2:44:21 AM10/22/12
to ne...@googlegroups.com
Hi,
      When you perform  g = TinkerGraphFactory.createTinkerGraph()  , the database that you were pointing before would be lost as you are creating a new instance of g. How will we access the old database now ?? Can't it be achieved without using TinkerGraphFactory ??

Stephen Mallette

unread,
Oct 22, 2012, 5:54:37 AM10/22/12
to ne...@googlegroups.com
"g" is just a variable and TinkerGraphFactory.createTinkerGraph(), was
just used for fully demonstrable code. You don't need to create a
TinkerGraph to create a step. Just define your step and use it
against your instance of "g" or whatever variable name you choose.

Stephen
> --
>
>
Reply all
Reply to author
Forward
0 new messages