英文:
Convert GRAPHSON_V2D0 Serializer response to GRAPHSON
问题
Azure Cosmos支持Serializers.GRAPHSON_V2D0。 List<Result> resultList = client.submit("g.V().limit(1)").all().get() 返回了与顶点一起的所有属性,并且格式完全不同。 Result 看起来像:
{
	"resultObject": {
		"id": "63073513-1e86-49e6-a949-07f1e16c782b",
		"label": "TYPE-1",
		"type": "vertex",
		"properties": {
			"prop1": [
				{
					"id": "63073513-1e86-49e6-a949-07f1e16c782b",
					"value": "value1"
				}
			],
			
		}
	}
}
但如果我在TinkerGraph中使用遍历, 默认结果使用 Serializers.GRAPHSON,结果看起来像:
[
	{
		"id": "63073513-1e86-49e6-a949-07f1e16c782b",
		"label": "TYPE-1"
	}
]
对于小型结果,我们可以添加一层来转换结果,但对于复杂的 Path 和其他查询来说可能不会那么简单。我尝试过 GraphSONMapper 但没有成功。是否有办法将Serializers.GRAPHSON_V2D0 转换为 Serializers.GRAPHSON?或者我们能否从Cosmos获取GraphSON结果?
英文:
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?
答案1
得分: 1
这实际上与序列化器无关。这是因为默认情况下,Gremlin Server仅返回顶点的"引用元素"。它只包含其ID和标签。您可以通过编辑位于<gremlin-server-root>/scripts文件夹中的脚本文件来禁用它。在那里,使用的默认文件称为empty-sample.groovy。在该文件底部,您将找到这行:
globals << [g : traversal().withEmbedded(graph).withStrategies(ReferenceElementStrategy)]
您只需要将其替换为:
globals << [g : traversal().withEmbedded(graph)]
完成后,重新启动服务器,您应该能够看到所有属性以及ID和标签。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论