Bill Poole created TINKERPOP-2789:
-------------------------------------

             Summary: Gremlin.Net cannot distinguish between an array parameter 
and a parameter array
                 Key: TINKERPOP-2789
                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2789
             Project: TinkerPop
          Issue Type: Bug
          Components: dotnet
    Affects Versions: 3.6.1
            Reporter: Bill Poole


When an array is passed to a step (e.g., "inject(array)"), Gremlin.Net always 
"flattens" the array into separate parameters, assuming it is a parameter list 
(e.g., "inject(p1, p2, p3, ...)").

This means that traversals in Gremlin.Net are not strictly correct when passing 
an array parameter. For example, this traversal below should actually require 
an "unfold" step:

 
{code:java}
await g.Inject<object>(array).Promise(t => t.ToList()); {code}
i.e., it should be:

 

 
{code:java}
await g.Inject<object>(array).Unfold<object>().Promise(t => t.ToList()); {code}
This means that certain traversals like in the [Long 
Traversals|https://tinkerpop.apache.org/docs/current/recipes/#long-traversals] 
recipe shown below do not work in Gremlin.Net because the "unfold" step needs 
to be removed.
{code:java}
g.withSideEffect("rels", relations).
           inject(persons).sideEffect(
             unfold().
             addV("person").
               property(id, select("id")).
               property("name", select("name")).
               property("age", select("age")).
             group("m").
               by(id).
               by(unfold())).
           select("rels").unfold().as("r").
           addE("knows").
             from(select("m").select(select("r").select("from"))).
             to(select("m").select(select("r").select("to"))).
             property("since", select("since")).iterate() {code}
I recognize that the C# language doesn't allow method overloads to distinguish 
between an array parameter and a params array. But as it stands, it is 
impossible to pass an array parameter to a step, so I think this needs to be 
remedied somehow.

One possible solution could be for steps that accept a params array (like 
"inject") to inspect the given type parameter to determine if it is an 
array/list/collection and if so, recognize that the parameter being passed is 
an array. An extra bool parameter could then be passed to the Bytecode.AddStep 
method to specify whether the parameter being passed should be "flattened", 
which should only be the case if the parameter passed to the step (like 
"inject") was _not_ an array/list/collection - i.e., it was a params array.

This same solution could also address the issue with 
GraphTraversalSource.WithSideEffect, where if an array parameter is passed, the 
Bytecode.AddSource method incorrectly flattens the array elements into separate 
parameters, which causes the server to throw an exception because its seeing 
"withSideEffect" being invoked with more parameters than expected.

 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to