Cosmos Db: SQL API + Graph API -- Really multi-model?
Asked Answered
E

1

6

This is my scenario: I want to have one single collection where I can insert and query documents using SqlApi and create vertices and edges using Graph Api, all in the same collection. I believed that that was possible taken into account what I've read on the documentations.

My first try was using Microsoft.Azure.Graphs.dll With this approach I was able to do CRUD operations with the Sql Api and execute gremlin scripts against the collection. It is important to note that the documents created with the Sql api Insert command where used as vertices. Then I created edges using the graph api connecting the documents created with the Sql Api. This works as expected. The only problem I had was that if the document contains an array property the graph Api returned and error : Invalid cast from 'System.String' to 'Newtonsoft.Json.Linq.JObject'. After investigating I was told that the Microsoft.Azure.Graphs.dll was deprecated and I should use Gremlin.Net instead. I have not read in any place that this assembly is deprecated and even in the official documentation and examples I can see that this assembly is being used. Is it really deprecated? Should I not use it?

Then this was my second try: I moved to Gremlin.net.

  • First issue: I was connecting to a collection created originally for Sql Api. When I tried to connect with Gremlin.Net Client it tolds me that can not connect to the server. When I created another database and collection for graph Api I was able to connect. Conclusion: It's not possible to use Gremlin.net with a collection created with Sql Api. Or is it possible to activate the gremlin endpoint in a database with Sql Api?

Using the new collection for Graph Api I tried again to create documents with the Sql Api and then connect using Graph Api. I see that in this case both endpoints are created: SqlApi+Gremlin. I had a few problems making this works. For example I had to set the GraphSon writer and reader to version 2, if not I received a null reference exception.

  • Second issue: I was able to create documents with Sql Api but I had the same problem with the array property (Example Document { "id":"aaa" "Prop": [ "1", "2"] } ) I get the same error when I query with gremlin: g.V('aaa') => Invalid cast from 'System.String' to 'Newtonsoft.Json.Linq.JObject'. Conclusion: My first issue with previous library was not solved with the new one.

  • Third issue: The json returned when I query with SqlApi the edges or vertices are different from received when I used Microsoft.Azure.Graphs.dll. It looks like the cosmos db engine handles differently the gremlin scripts depending on the assembly. Which the json format I should expect?

Notes:

-Why I need to create vertices using SqlApi? Because I want to create properties with custom objects and I'm not able to do it with graphApi: Example: { "Id": "aaa", "Custom" : { "Id": 456, "Code" : { "Id": 555, "Name": "Hi"} }

-Why I want to query graph using SqlApi? Because I want to access my custom properties. Because I want to paginate using tokens. (Range gremlin function it is not performant. It traverse all the vertex/edges from 0 to the last page I want)

Has someone some information about this situations? Help will be appreciated.

Emelineemelita answered 24/6, 2018 at 20:7 Comment(5)
To connect with Gremlin.Net you need to use another endpointAnhwei
Thanks Tony. I realize that after a couple of tries. What it seems strage to me is that I was able to create vertices using the previous (deprecated?) assembly propossed by Azure.Emelineemelita
Maybe this can help #48169856Anhwei
Any news on this question? I have a Cosmos DB created with SQL API, but would like to use the stored documents as vertices, and created edges between these vertices using the Gremlin API...Oxley
I'm not sure if this helps @SergevandenOever , but it looks like this post suggests you can use both the sqlapi and gremlin api: vincentlauzon.com/2017/09/05/…Excise
E
0

I know this post is a bit older, but it looks like it is possible to use graph and sql api. The key is in adopting the gremlin's underlying storage format when using the sql api for querying/manipulating. Please check this post out: https://vincentlauzon.com/2017/09/05/hacking-accessing-a-graph-in-cosmos-db-with-sql-documentdb-api/

Excise answered 24/2, 2022 at 0:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.