Error when trying to read ElementMap from Edge in Gremlin.Net: The given key 'janusgraph.RelationIdentifier' was not present in the dictionary #gremlin-dotnet


tormodhau@...
 

Hi!

When I try to read the ElementMap of an edge in Gremlin.Net:

        var edgeValues = g.E()
            .Has("Mrid", "..guid..")
            .ElementMap<object>()
            .Next();            // <---- Throws here

I get the following error:

       System.Collections.Generic.KeyNotFoundException : The given key 'janusgraph.RelationIdentifier' was not present in the dictionary.

Environment:

       JanusGraph, ElasticSearch, Cassandra (the official docker-compose running locally)
       Gremlin.Net 3.6.1
       Dotnet Core 6.4.0

Full example (unit test with xUnit):
       
    [Fact]
    public void AddingEdgeBetweenTwoVertexes()
    {
        // Start a Janusgraph + Cassandra + ElasticSearch environment with docker compose:
        // https://github.com/JanusGraph/janusgraph-docker/blob/master/docker-compose-cql-es.yml
        var gremlinServer = new GremlinServer("localhost", 8182);
        var gremlinClient = new GremlinClient(gremlinServer);
        var remoteConnection = new DriverRemoteConnection(gremlinClient, "g");
        var g = AnonymousTraversalSource.Traversal().WithRemote(remoteConnection);
        g.V().Drop().Iterate();
        g.E().Drop().Iterate();
 
        var firstMrid = Guid.NewGuid();
        g.AddV("V1")
            .Property("Mrid", firstMrid)
            .Iterate();
 
        var secondMrid = Guid.NewGuid();
        g.AddV("V2")
            .Property("Mrid", secondMrid)
            .Iterate();
 
        var edgeMrid = Guid.NewGuid();
        g.AddE("E1")
            .Property("Mrid", edgeMrid)
            .Property("Name", "Hello Edge")
            .From(__.V().Has("Mrid", firstMrid))
            .To(__.V().Has("Mrid", secondMrid))
            .Iterate();
 
        // Verify that two vertices and one edge is added
        Assert.Equal(1, g.E().Count().Next());
        Assert.Equal(2, g.V().Count().Next());
 
        var edgeValues = g.E()
            .Has("Mrid", edgeMrid)
            .ElementMap<object>()
            .Next();            // <---- Throws here
 
        Assert.Equal("Hello Edge", edgeValues["Name"]);
    }

Full error:


     [xUnit.net 00:00:02.06]     tests.Graph.GremlinExplorationTest.AddingEdgeBetweenTwoVertexes_ [FAIL]
  Failed tests.Graph.GremlinExplorationTest.AddingEdgeBetweenTwoVertexes_ [465 ms]
  Error Message:
   System.Collections.Generic.KeyNotFoundException : The given key 'janusgraph.RelationIdentifier' was not present in the dictionary.
  Stack Trace:
     at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Gremlin.Net.Structure.IO.GraphBinary.TypeSerializerRegistry.GetSerializerForCustomType(String typeName)
   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryReader.ReadAsync(Stream stream)
   at Gremlin.Net.Structure.IO.GraphBinary.Types.MapSerializer`2.ReadValueAsync(Stream stream, GraphBinaryReader reader)
   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadValueAsync(Stream stream, GraphBinaryReader reader, Boolean nullable)
   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadAsync(Stream stream, GraphBinaryReader reader)
   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryReader.ReadAsync(Stream stream)
   at Gremlin.Net.Structure.IO.GraphBinary.Types.TraverserSerializer.ReadValueAsync(Stream stream, GraphBinaryReader reader)
   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadValueAsync(Stream stream, GraphBinaryReader reader, Boolean nullable)
   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadAsync(Stream stream, GraphBinaryReader reader)
   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryReader.ReadAsync(Stream stream)
   at Gremlin.Net.Structure.IO.GraphBinary.Types.ListSerializer`1.ReadValueAsync(Stream stream, GraphBinaryReader reader)
   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadValueAsync(Stream stream, GraphBinaryReader reader, Boolean nullable)
   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadAsync(Stream stream, GraphBinaryReader reader)
   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryReader.ReadAsync(Stream stream)
   at Gremlin.Net.Structure.IO.GraphBinary.ResponseMessageSerializer.ReadValueAsync(MemoryStream stream, GraphBinaryReader reader)
   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryMessageSerializer.DeserializeMessageAsync(Byte[] message)
   at Gremlin.Net.Driver.Connection.HandleReceivedAsync(Byte[] received)
   at Gremlin.Net.Driver.Connection.ReceiveMessagesAsync()
   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.MoveNext()
   at Gremlin.Net.Process.Traversal.DefaultTraversal`2.Next()
   at tests.Graph.GremlinExplorationTest.AddingEdgeBetweenTwoVertexes_() in /Users/tormodhaugene/customers/volue/spark-grid/tests/Graph/GremlinExplorationTest.cs:line 130
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)


Does anyone know what this error means or how to avoid it? I am at a loss on how to debug it.

- Tormod


Florian Hockmann
 

Hi,

 

`RelationIdentifier` is a type specific to JanusGraph which is why Gremlin.Net cannot know how to deserialize it. We have built a library that extends Gremlin.Net with JanusGraph specific types to solve this: https://github.com/JanusGraph/janusgraph-dotnet/

 

You can simply create a JanusGraphGraphSONMessageSerializer or a GraphBinaryMessageSerializer with the JanusGraphTypeSerializerRegistry.Instance and provide that to the constructor of GremlinClient.

 

Von: janusgraph-users@... <janusgraph-users@...> Im Auftrag von tormodhau@...
Gesendet: Montag, 9. Januar 2023 10:25
An: janusgraph-users@...
Betreff: [janusgraph-users] Error when trying to read ElementMap from Edge in Gremlin.Net: The given key 'janusgraph.RelationIdentifier' was not present in the dictionary #gremlin-dotnet

 

Hi!

When I try to read the ElementMap of an edge in Gremlin.Net:

        var edgeValues = g.E()

            .Has("Mrid", "..guid..")

            .ElementMap<object>()

            .Next();            // <---- Throws here


I get the following error:

       System.Collections.Generic.KeyNotFoundException : The given key 'janusgraph.RelationIdentifier' was not present in the dictionary.

Environment:

       JanusGraph, ElasticSearch, Cassandra (the official docker-compose running locally)
       Gremlin.Net 3.6.1
       Dotnet Core 6.4.0

Full example (unit test with xUnit):
       
    [Fact]

    public void AddingEdgeBetweenTwoVertexes()

    {

        // Start a Janusgraph + Cassandra + ElasticSearch environment with docker compose:

        var gremlinServer = new GremlinServer("localhost", 8182);

        var gremlinClient = new GremlinClient(gremlinServer);

        var remoteConnection = new DriverRemoteConnection(gremlinClient, "g");

        var g = AnonymousTraversalSource.Traversal().WithRemote(remoteConnection);

        g.V().Drop().Iterate();

        g.E().Drop().Iterate();

 

        var firstMrid = Guid.NewGuid();

        g.AddV("V1")

            .Property("Mrid", firstMrid)

            .Iterate();

 

        var secondMrid = Guid.NewGuid();

        g.AddV("V2")

            .Property("Mrid", secondMrid)

            .Iterate();

 

        var edgeMrid = Guid.NewGuid();

        g.AddE("E1")

            .Property("Mrid", edgeMrid)

            .Property("Name", "Hello Edge")

            .From(__.V().Has("Mrid", firstMrid))

            .To(__.V().Has("Mrid", secondMrid))

            .Iterate();

 

        // Verify that two vertices and one edge is added

        Assert.Equal(1, g.E().Count().Next());

        Assert.Equal(2, g.V().Count().Next());

 

        var edgeValues = g.E()

            .Has("Mrid", edgeMrid)

            .ElementMap<object>()

            .Next();            // <---- Throws here

 

        Assert.Equal("Hello Edge", edgeValues["Name"]);

    }


Full error:


     [xUnit.net 00:00:02.06]     tests.Graph.GremlinExplorationTest.AddingEdgeBetweenTwoVertexes_ [FAIL]

  Failed tests.Graph.GremlinExplorationTest.AddingEdgeBetweenTwoVertexes_ [465 ms]

  Error Message:

   System.Collections.Generic.KeyNotFoundException : The given key 'janusgraph.RelationIdentifier' was not present in the dictionary.

  Stack Trace:

     at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

   at Gremlin.Net.Structure.IO.GraphBinary.TypeSerializerRegistry.GetSerializerForCustomType(String typeName)

   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryReader.ReadAsync(Stream stream)

   at Gremlin.Net.Structure.IO.GraphBinary.Types.MapSerializer`2.ReadValueAsync(Stream stream, GraphBinaryReader reader)

   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadValueAsync(Stream stream, GraphBinaryReader reader, Boolean nullable)

   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadAsync(Stream stream, GraphBinaryReader reader)

   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryReader.ReadAsync(Stream stream)

   at Gremlin.Net.Structure.IO.GraphBinary.Types.TraverserSerializer.ReadValueAsync(Stream stream, GraphBinaryReader reader)

   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadValueAsync(Stream stream, GraphBinaryReader reader, Boolean nullable)

   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadAsync(Stream stream, GraphBinaryReader reader)

   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryReader.ReadAsync(Stream stream)

   at Gremlin.Net.Structure.IO.GraphBinary.Types.ListSerializer`1.ReadValueAsync(Stream stream, GraphBinaryReader reader)

   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadValueAsync(Stream stream, GraphBinaryReader reader, Boolean nullable)

   at Gremlin.Net.Structure.IO.GraphBinary.Types.SimpleTypeSerializer`1.ReadAsync(Stream stream, GraphBinaryReader reader)

   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryReader.ReadAsync(Stream stream)

   at Gremlin.Net.Structure.IO.GraphBinary.ResponseMessageSerializer.ReadValueAsync(MemoryStream stream, GraphBinaryReader reader)

   at Gremlin.Net.Structure.IO.GraphBinary.GraphBinaryMessageSerializer.DeserializeMessageAsync(Byte[] message)

   at Gremlin.Net.Driver.Connection.HandleReceivedAsync(Byte[] received)

   at Gremlin.Net.Driver.Connection.ReceiveMessagesAsync()

   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.MoveNext()

   at Gremlin.Net.Process.Traversal.DefaultTraversal`2.Next()

   at tests.Graph.GremlinExplorationTest.AddingEdgeBetweenTwoVertexes_() in /Users/tormodhaugene/customers/volue/spark-grid/tests/Graph/GremlinExplorationTest.cs:line 130

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)

   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)



Does anyone know what this error means or how to avoid it? I am at a loss on how to debug it.

- Tormod


tormodhau@...
 

Hi, Florian!

Thank you so much! I have found this repository during my research, but I didn't understand why it was needed at the time. It makes total sense now.

Now, the exception thrown might seem a little confusing. Do you think it would be viable to catch the  KeyNotFoundException  inside. TypeSerializerRegistry (or similar), and then give a better explanation? An exception saying e.g "Serializer for type ''janusgraph..xx' was not found. See documentation on custom serializers [...]" would be much more telling on where to look. 

Would you like me to add this as an issue in the Janusgraph repo?


Florian Hockmann
 

A better exception would really be a good idea. This is however an issue in TinkerPop and not JanusGraph as the Gremlin.Net driver belongs to TinkerPop.

 

I went ahead and created an issue for this in the TinkerPop project: https://issues.apache.org/jira/browse/TINKERPOP-2853

 

Registration for this Jira instance is closed unfortunately due to problems with spam so you would have to ask for an account to be created which is why I thought that it might be to easier if I just go ahead and create the issue myself.

 

But you can of course create a PR to improve this if you want. The repository is: https://github.com/apache/tinkerpop

 

 

Von: janusgraph-users@... <janusgraph-users@...> Im Auftrag von tormodhau@...
Gesendet: Dienstag, 10. Januar 2023 08:18
An: janusgraph-users@...
Betreff: Re: [janusgraph-users] Error when trying to read ElementMap from Edge in Gremlin.Net: The given key 'janusgraph.RelationIdentifier' was not present in the dictionary #gremlin-dotnet

 

Hi, Florian!

Thank you so much! I have found this repository during my research, but I didn't understand why it was needed at the time. It makes total sense now.

Now, the exception thrown might seem a little confusing. Do you think it would be viable to catch the  KeyNotFoundException  inside. TypeSerializerRegistry (or similar), and then give a better explanation? An exception saying e.g "Serializer for type ''janusgraph..xx' was not found. See documentation on custom serializers [...]" would be much more telling on where to look. 

Would you like me to add this as an issue in the Janusgraph repo?