5

Starting from the Azure Cosmos DB Graph API example: https://github.com/Azure-Samples/azure-cosmos-db-graph-gremlindotnet-getting-started

I am interested in using Gremlin.NET (the example uses version 3.2.7) to execute queries using the C# classes instead of writing string queries and execute them using the gremlinClient.SubmitAsync<dynamic>("...") method.

But when I execute the following code I'm getting a

NullReferenceException at Gremlin.Net.Driver.Connection.d__14`1.MoveNext()

when calling .Next()

var gremlinServer = new GremlinServer(hostname, port, enableSsl: true,
    username: "/dbs/" + database + "/colls/" + collection,
    password: authKey);

var graph = new Graph();
var g = graph.Traversal().WithRemote(new DriverRemoteConnection(new GremlinClient(gremlinServer)));

var vertex = g.V().HasLabel("person").Next();
Console.WriteLine(vertex);

Unfortunately I haven't found any documentation on how to use Gremlin.NET it would be nice if someone of you can point me to some "getting started".

Edit: The query result from the Azure Cosmos DB Data Explorer looks like the following:

[
  {
    "id": "thomas",
    "label": "person",
    "type": "vertex",
    "properties": {
      "firstName": [
        {
          "id": "9015b584-375f-4005-af00-f49d6e2d6b94",
          "value": "Thomas"
        }
      ],
      "age": [
        {
          "id": "c2300d19-12a0-474a-9405-eb89466bcbb3",
          "value": 44
        }
      ]
    },
    "_isRoot": true,
    "_isFixedPosition": true
  }
]
Chris
  • 139
  • 10
  • 1
    Unfortunately, I can't post an answer as this was already marked as a duplicate. However, the reason why this doesn't work with Cosmos DB is that it doesn't support yet Gremlin Bytecode which is was is sent to the server when you use the traversal API as you did. So, your only option currently is to really write the queries as strings and just send those queries to the server. Regarding documentation: [Gremlin.Net specific aspects are explained here](http://tinkerpop.apache.org/docs/current/reference/#gremlin-DotNet), nearly everything else of the docs also applies to Gremlin.Net. – Florian Hockmann Mar 14 '18 at 14:53
  • 1
    Hi @FlorianHockmann thanks for your answer. I would accept it if it was possible.. ;-). Anyway I posted a suggestion to support Gremlin Bytecode in Azure Cosmos DB, see: https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/33632779-support-gremlin-bytecode-to-enable-the-fluent-api – Chris Mar 14 '18 at 15:42
  • 1
    I converted my comment into an answer. BTW: You mentioned that you didn't find any documentation. I provided a few links in my answer, but if you still have suggestions for improvements then you can [create an issue](https://issues.apache.org/jira/projects/TINKERPOP/issues) and pull requests that improve the documentation are of course also always welcome. – Florian Hockmann Mar 14 '18 at 18:17
  • 1
    Suggestions to support Gremlin ByteCode has now 3 more votes If you read these lines and agree with above suggestion and want to contribute then you're very welcome to vote. It's free... – PeteZaria Jun 08 '18 at 13:39

1 Answers1

5

The reason why this doesn't work with Cosmos DB is simply that Cosmos DB doesn't support Gremlin Bytecode yet which is what is sent to the server when you use the traversal API as you did. So, your only option currently is to really write the queries as strings and just send those query strings to the server.

Regarding documentation: Gremlin traversals can be written in different languages (see The Gremlin Graph Traversal Machine and Language for more information about Gremlin in general). Therefore the TinkerPop docs also apply to Gremlin.Net and the Gremlin.Net part of the documentation only explains the aspects that are really specific to Gremlin.Net.

Florian Hockmann
  • 2,249
  • 9
  • 23