Why parsing Gremlin query in Java isn't generic? -
i'm parsing gremlin query in java (well, i'm writing scala, , using groovy compiled jars java).
the query string variable given user input. in other words - cannot tell query be, i'm assuming it's valid gremlin query (syntactically , logically).
i started simple gremlin.compile(query)
returns pipe
on i'm iterating. however, according the example, 1 must invoke .setstarts
prior iterating pipe. , must know runtime type s
in pipe<s,e>
.
it feels api isn't generic enough, following line example
pipe.setstarts(new singleiterator<vertex>(graph.getvertex(1)));
will work cases, vertex iteration 1 example (g.v()
) throw castexception.
is there way work-around it?
perhaps using underlying script engine (like next examples in link above) me achieve more generic code?
i found workaround. feels bit ugly job.
i'm using
scriptengine
bindings
of 'g' graph, user can start his/her queriesg.
. (not helps generics, makes more user-friendly not making user use identity pipe (_()
) @ beginning of his/her queries).(kind of ugly, know) i'm extracting query string (using regex) starting vertex (if exists), finding programatically , (if found) invoking setstarts it. if it's not found i'm giving graph parameter setstarts, assuming vertex iteration query.
Comments
Post a Comment