Hi Luca,
I have found a side effect in fix for issue 507.
Assuming that we pass variables from the client, e.g.:
params.put("map1", new HashMap());
params.put("map2", new HashMap());
Every call to execute(final ORecord<?> iCurrentRecord, final Object[]
iParameters, final OCommandExecutor iRequester) in OSQLFunctionGremlin
would expect a new fresh instance of each variable. However, at the
moment, the same instance passed from the client, is being reused in
all calls to execute(). So results area wrongly aggregated for each
loop execution. I think this is extensible to any other call for
functions. Please confirm that this idea matches also with how you
think functions should work.
I figure out 3 possible fixes:
1* in every call to execute() passing a clone() of the original input
variable rather than, always, the instance propagated from the client.
I do not know how feasible is doing clone() and how can impact on
performance.
2* do a clear() of removeAll() or .... to initialize the variable
every time execute() is called when they are collections. This could
be bad if we want to pass pre-loaded variables.
3* one more thing to configure from the invoker Java client to
transfer this flexibility to the user.
The less intrusive, at the moment, I think is doing a clear() inside
the Gremlin function (2), so it will keep as a local fix, pending to
learn more about necessities on passing parameters to other functions.
WDYT?
Adolfo
> On 7 October 2011 00:07, Adolfo Rodriguez <
pellyado...@yahoo.es> wrote:
>
>
>
>
>
>
>
> > Hi Luca,
>
> > I do not think there is enough new content yet to create a new page,
> > considering that is pending to investigate more output configurations.
> > I will leave pending to clarify the best mechanism to define outputs.
> > For the moment I have written the text below that can be added just
> > above 'Conclusion' on the Gremlin wiki page, for example. I think it
> > mentions the 2 new concepts here: input params/variables and output.
>
> > --------------------------------------------------------------------------- --------------------------------------
>
> > PASSING INPUT PARAMETERS
> > Some Gremlin expressions require declaration of input parameters to be
> > run. This is the case, for example, of bound variables, as described
> > in JSR 223 GremlinScriptEngine (
https://github.com/tinkerpop/gremlin/
> > wiki/Using-Gremlin-through-Java). OrientDB has enabled a mechanism to
> > pass variables to a Gremlin pipeline declared in a command as
> > described below:
>
> > Map<String, Object> params = new HashMap<String, Object>();
> > params.put("map1", new HashMap());
> > params.put("map2", new HashMap());
> > db.command(new OCommandSQL("select gremlin('
> >
current.as
> > ('id').outE.label.groupCount(map1).optional('id').sideEffect{map2=it.map(); map2+=map1;}
> > ')")).execute(params);
>
> > DECLARING OUTPUT
> > In the simplest case, the output of the last step (
https://github.com/
> > tinkerpop/gremlin/wiki/Gremlin-Steps) in the Gremlin pipeline
> > corresponds to the output of the overall Gremlin expression. However,
> > it is possible to instruct the Gremlin engine to consider any of the
> > input variables as output. This can be declared as:
>
> > Map<String, Object> params = new HashMap<String, Object>();
> > params.put("map1", new HashMap());
> > params.put("map2", new HashMap());
> > params.put("output", "map2");
> > db.command(new OCommandSQL("select gremlin('
> >
current.as
> > ('id').outE.label.groupCount(map1).optional('id').sideEffect{map2=it.map(); map2+=map1;}
> ...
>
> read more »