0

Azure cosmos support Serializers.GRAPHSON_V2D0. List<Result> resultList = client.submit("g.V().limit(1)").all().get() returns all the properties with the vertex and the format is completely different. Result looks like

{
    "resultObject": {
        "id": "63073513-1e86-49e6-a949-07f1e16c782b",
        "label": "TYPE-1",
        "type": "vertex",
        "properties": {
            "prop1": [
                {
                    "id": "63073513-1e86-49e6-a949-07f1e16c782b",
                    "value": "value1"
                }
            ],
            
        }
    }
}

But if I use Traversal with TinkerGraph, the default result uses Serializers.GRAPHSON where the result looks like

[
    {
        "id": "63073513-1e86-49e6-a949-07f1e16c782b",
        "label": "TYPE-1"
    }
]

For small result we can put a layer to covert the result but won't be straight forward thing for complex Path and other queries. I tried GraphSONMapper but didn't work. Is there any way to convert Serializers.GRAPHSON_V2D0 to Serializers.GRAPHSON? Or can we get GraphSON result from Cosmos?

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
Sanjay Sharma
  • 3,687
  • 2
  • 22
  • 38
  • Are you using TinkerGraph with a Gremlin Server or some other configuration? If with Gremlin Server you can configure the server to return any of the supported serialization formats. – Kelvin Lawrence Feb 27 '23 at 14:11
  • Actually I don't have that option to change the response format as the response is consumed by multiple clients so I'm trying to find a way to get the same result on Cosmos Gremlin DB. – Sanjay Sharma Feb 27 '23 at 16:37
  • Ah actually, I understand what you need now. I will add an answer – Kelvin Lawrence Feb 27 '23 at 19:02
  • I tried to use Serializers.GRAPHSON_V2D0 while creating Cluster object for Neptune then it returned same result as Cosmos. By default it uses Serializers.GRAPHSON_V3D0/Serializers.GRAPHSON and send the MIME type accordingly so the response are different in both the cases. – Sanjay Sharma Feb 28 '23 at 04:25

1 Answers1

1

This is not actually due to the serializers. It is due to the fact that, by default, Gremlin Server only returns a "Reference Element" for a vertex. It will just contain its ID and label. You can disable that by editing the script file in the <gremlin-server-root>/scripts folder. In there, the default file used is called empty-sample.groovy. At the bottom of that file you will find this line:

globals << [g : traversal().withEmbedded(graph).withStrategies(ReferenceElementStrategy)]

All you need to do is to replace it with just

globals << [g : traversal().withEmbedded(graph)]

Having done that, restart the server and you should see all properties as well as the ID and label.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • Can we do that on cosmos DB? – Sanjay Sharma Feb 28 '23 at 04:20
  • This is something you can do to make a Gremlin Server match what you mentioned you are getting back from CosmosDB (nodes that include all their property values).. There are two different things in play here. (1) disabling the ReferenceElementStrategy for Gremlin server to enable getting properties back, and (2) Using GraphSONV2 everywhere so that whichever DB you connect to - Gremlin Server/Amazon Neptune/CosmosDB - you will get the same serialization. Currently Neptune will only return a ReferenceElement however. Making that user configurable is on the Apache TinkerPop roadmap. – Kelvin Lawrence Feb 28 '23 at 21:51
  • It might be better to explicitly ask for the properties you need using either `valueMap` or `elementMap` rather than rely on a specific DB behavior. That way you will have more control over the data that is returned regardless of the back-end implementation. – Kelvin Lawrence Feb 28 '23 at 21:54
  • Looks like impossible as of now as Cosmos has so many limitations. Explicitly getting the values is the option we had in mind, but this involves changes at consumers end as well. Thanks @Kelvin! – Sanjay Sharma Mar 01 '23 at 13:29