Exception on Limit() with Gremlin.Net

245 Views Asked by At

I am looking to make a query with Gremlin.net on a JanusGraph server, who will find the best route in my Graph (between one point and another, the best route).

To replay the error

I made a repo on Github with a sample application. source Github, it's the project "TestGremlinNet".
I use a docker container, janusgraph.

docker run --name janusgraph -d -p 8180:8182 janusgraph/janusgraph:latest

This is a test project to see how JanusGraph and the Gremlin.net library work. I use data from the game EveOnline. I create a Graph that represents solar systems and the connections between systems. The goal is to calculate the route from one point to another.
The universe is divided into regions, and in one region there are several solar systems.
I put a site that calculates routes, and this represents the graph of a region: "The Forge". dotlan

To test, I'm trying to calculate the route "Jita" to "Mitsolen" with the method :

await loadData.Test("Jita", "Mitsolen");

These are the tests I have done.

Here's my 1st test :
var allSystems = GremlinRequest.V().HasLabel("SystemSolar").Has("SolarSystemName", start)
                        .Repeat(__.Out().SimplePath())
                        .Until(__.HasLabel("SystemSolar").Has("SolarSystemName", arrive))
                        .Path()
                        .Limit<Vertex>(1)
                        .Project<Object>("SolarSystemId", "SolarSystemName", "Securite", "RegionName")
                        .By("SolarSystemId")
                        .By("SolarSystemName")
                        .By("Securite")
                        .By("RegionName")
                        .ToList();

Result :

ServerError: The by("SolarSystemId") modulator can only be applied to a traverser that is an Element or a Map 
- it is being applied to [path[v[41112], v[110776], v[118968], v[53296], v[41136]]] 
a ImmutablePath class instead

The [path[v[41112], v[110776], v[118968], v[53296] are all Vertice's ID of my route, so my query is good. Ok he cant apply .By(...) on .Path(), so I changed my request not to make a projection, and to recover the Path directly :

2nd/3rd/4th tests :
var allSystems = GremlinRequest.V().HasLabel("SystemSolar").Has("SolarSystemName", start)
                        .Repeat(__.Out().SimplePath())
                        .Until(__.HasLabel("SystemSolar").Has("SolarSystemName", arrive))
                        .Path()
                        .Limit<Vertex>(1)
                        // Tested with .Unfold<Vertex>() too...
                        .ToList();
                        // and Tested with .Next(); too...

I have a Exception :

Exception Message : 
ServerError:

StackTrace : 
   at Gremlin.Net.Driver.Messages.ResponseStatusExtensions.ThrowIfStatusIndicatesError(ResponseStatus status)
   at Gremlin.Net.Driver.Connection.HandleReceivedMessage(ResponseMessage`1 receivedMsg)
   at Gremlin.Net.Driver.Connection.HandleReceivedAsync(Byte[] received)
   at Gremlin.Net.Driver.ProxyConnection.SubmitAsync[T](RequestMessage requestMessage)
   at Gremlin.Net.Driver.GremlinClient.SubmitAsync[T](RequestMessage requestMessage)
   at Gremlin.Net.Driver.Remote.DriverRemoteConnection.SubmitBytecodeAsync(Guid requestid, Bytecode bytecode)
   at Gremlin.Net.Driver.Remote.DriverRemoteConnection.SubmitAsync[S,E](Bytecode bytecode)
   at Gremlin.Net.Process.Remote.RemoteStrategy.ApplyAsync[S,E](ITraversal`2 traversal)
   at Gremlin.Net.Process.Utils.WaitUnwrap(Task task)
   at Gremlin.Net.Process.Remote.RemoteStrategy.Apply[S,E](ITraversal`2 traversal)
   at Gremlin.Net.Process.Traversal.DefaultTraversal`2.ApplyStrategies()
   at Gremlin.Net.Process.Traversal.DefaultTraversal`2.GetTraverserEnumerator()
   at Gremlin.Net.Process.Traversal.DefaultTraversal`2.get_TraverserEnumerator()
   at Gremlin.Net.Process.Traversal.DefaultTraversal`2.MoveNextInternal()
   at Gremlin.Net.Process.Traversal.DefaultTraversal`2.ToList()
   at GremlinDriver.Loader.<>c__DisplayClass11_0.<Test>b__0()
5th test :

Try to recover all routes.

var allSystems = GremlinRequest.V().HasLabel("SystemSolar").Has("SolarSystemName", start)
                        .Repeat(__.Out().SimplePath())
                        .Until(__.HasLabel("SystemSolar").Has("SolarSystemName", arrive))
                        .Path()
                        .ToList();

With the result more 7100 possible paths :

{path[v[41112], v[110776], v[118968], v[53296], v[41136]]} // <--- It's mine !
{path[v[41112], v[106680], v[110776], v[118968], v[53296], v[41136]]}
and more...

I have my result, but its killing my memory and performance !

If you have any ideas.
Thank you for your help.

Edit :

6th test :
var allSystems = GremlinRequest.V().HasLabel("SystemSolar").Has("SolarSystemName", depart) //vdepart.Id
                                            .Repeat(__.Out().SimplePath())
                                            .Until(__.HasLabel("SystemSolar").Has("SolarSystemName", arrive)) //.V(varrive.Id)
                                            .Path()
                                            .By("SolarSystemName")
                                            .ToList();

I have more 7000 results, but with this aspect :

{path[Jita, New Caldari, Josameto, Poinen, Nomaa]}
{path[Jita, New Caldari, Josameto, Liekuri, Poinen, Nomaa]}
.....+7000

When I'm adding .Limit<string>(1), I have the exception.

1

There are 1 best solutions below

0
On

I found the problem. The problem come to JanusDb. With a Gremlin server I have no problem, and here is the code to get the shortest path, and with the return in object form.
Run docker Gremlin :

docker run -d tinkerpop/gremlin-server:latest

and the code :

internal Task<List<SolarSystem>> GetItineraire(string depart, string arrive)
{
    return Task.Factory.StartNew(() =>
    {
        List<SolarSystem> systemsRegion = new List<SolarSystem>();

        try
        {
            Path allSystems = GremlinRequest.V().HasLabel(LABEL_VERTEX).Has(SOLAR_SYSTEM_NAME, depart)
                                    .Repeat(__.Out().SimplePath())
                                    .Until(__.HasLabel(LABEL_VERTEX).Has(SOLAR_SYSTEM_NAME, arrive))
                                    .Path()
                                    .Limit<Path>(1)
                                    .Next();

            foreach (var systemRoute in allSystems.Objects)
            {
                SolarSystem system = new SolarSystem();

                var etapeItineraire = GremlinRequest.V(((Vertex)systemRoute).Id)
                                                    .Project<Object>(SOLAR_SYSTEM_ID, SOLAR_SYSTEM_NAME, SECURITE, REGION_NAME)
                                                    .By(SOLAR_SYSTEM_ID)
                                                    .By(SOLAR_SYSTEM_NAME)
                                                    .By(SECURITE)
                                                    .By(REGION_NAME)
                                                    .Next();

                // Key : correspond au nom de la propriété
                // Value : la valeur de la propriété
                foreach (var etape in etapeItineraire)
                {
                    // Key : correspond au nom de la propriété
                    // Value : la valeur de la propriété
                    var property = typeof(SolarSystem).GetProperty(etape.Key);
                    property.SetValue(system, etape.Value);
                }

                systemsRegion.Add(system);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine("#############");
            Console.WriteLine(ex.StackTrace);
        }

        return systemsRegion;
    });
}