Gremlin.Net 中的 GraphJSON 序列化
GraphJSON serialization in Gremlin.Net
我正在尝试通过 CosmosDB client library 查询 TinkerPop 服务器(托管在 docker 容器内),它在后台使用 Gremlin.Net。所以我设法连接它并插入数据,这里是拦截的 WebSocket 请求:
!application/vnd.gremlin-v1.0+json{
"requestId": "b64bd2eb-46c3-4095-9eef-768bca2a14ed",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.addV(\"User\").property(\"UserId\",2).property(\"CustomerId\",1)"
}
}
回复:
{
"requestId": "b64bd2eb-46c3-4095-9eef-768bca2a14ed",
"status": {
"message": "",
"code": 200,
"attributes": {
"host": "/172.19.0.1:38848"
}
},
"result": {
"data": [
{
"id": 0,
"label": "User",
"type": "vertex",
"properties": {}
}
],
"meta": {}
}
}
问题是我在通过 gremlin 控制台连接时看到了这些属性
gremlin> g.V().hasLabel("User").has("CustomerId",1).has("UserId",2).limit(1).valueMap()
==>{UserId=[2], CustomerId=[1]}
此外,我可以使用 Gremlin.Net:
查询 TinkerPop 服务器
!application/vnd.gremlin-v1.0+json{
"requestId": "de35909f-4bc1-4aae-aa5f-28361b3c0933",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.V().hasLabel(\"User\").has(\"CustomerId\",1).has(\"UserId\",2).limit(1)"
}
}
但它 return 是一个具有零值 ID 且不包含任何属性的负载:
{
"requestId": "de35909f-4bc1-4aae-aa5f-28361b3c0933",
"status": {
"message": "",
"code": 200,
"attributes": {
"host": "/172.19.0.1:38858"
}
},
"result": {
"data": [
{
"id": 0,
"label": "User",
"type": "vertex",
"properties": {}
}
],
"meta": {}
}
}
尝试在 GraphSON v1、v2、v3 之间交换,但没有成功。文档说脚本序列化程序应该包括所有属性。我是否必须以某种方式调整配置才能使这项工作和 return 属性?
所以好像是3.4 of the Gremlin server ReferenceElementStrategy的版本
默认添加到遍历,以保持二进制和脚本序列化程序之间的兼容性。在我们的例子中,我们想模仿 CosmosDB 的行为,因此要调整和接收所需的行为,只需从 init 脚本中删除策略(在我们的例子中,它是 empty-sample.groovy
globals << [g : graph.traversal().withStrategies(ReferenceElementStrategy.instance())]
至
globals << [g : graph.traversal()]
我正在尝试通过 CosmosDB client library 查询 TinkerPop 服务器(托管在 docker 容器内),它在后台使用 Gremlin.Net。所以我设法连接它并插入数据,这里是拦截的 WebSocket 请求:
!application/vnd.gremlin-v1.0+json{
"requestId": "b64bd2eb-46c3-4095-9eef-768bca2a14ed",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.addV(\"User\").property(\"UserId\",2).property(\"CustomerId\",1)"
}
}
回复:
{
"requestId": "b64bd2eb-46c3-4095-9eef-768bca2a14ed",
"status": {
"message": "",
"code": 200,
"attributes": {
"host": "/172.19.0.1:38848"
}
},
"result": {
"data": [
{
"id": 0,
"label": "User",
"type": "vertex",
"properties": {}
}
],
"meta": {}
}
}
问题是我在通过 gremlin 控制台连接时看到了这些属性
gremlin> g.V().hasLabel("User").has("CustomerId",1).has("UserId",2).limit(1).valueMap()
==>{UserId=[2], CustomerId=[1]}
此外,我可以使用 Gremlin.Net:
查询 TinkerPop 服务器!application/vnd.gremlin-v1.0+json{
"requestId": "de35909f-4bc1-4aae-aa5f-28361b3c0933",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.V().hasLabel(\"User\").has(\"CustomerId\",1).has(\"UserId\",2).limit(1)"
}
}
但它 return 是一个具有零值 ID 且不包含任何属性的负载:
{
"requestId": "de35909f-4bc1-4aae-aa5f-28361b3c0933",
"status": {
"message": "",
"code": 200,
"attributes": {
"host": "/172.19.0.1:38858"
}
},
"result": {
"data": [
{
"id": 0,
"label": "User",
"type": "vertex",
"properties": {}
}
],
"meta": {}
}
}
尝试在 GraphSON v1、v2、v3 之间交换,但没有成功。文档说脚本序列化程序应该包括所有属性。我是否必须以某种方式调整配置才能使这项工作和 return 属性?
所以好像是3.4 of the Gremlin server ReferenceElementStrategy的版本
默认添加到遍历,以保持二进制和脚本序列化程序之间的兼容性。在我们的例子中,我们想模仿 CosmosDB 的行为,因此要调整和接收所需的行为,只需从 init 脚本中删除策略(在我们的例子中,它是 empty-sample.groovy
globals << [g : graph.traversal().withStrategies(ReferenceElementStrategy.instance())]
至
globals << [g : graph.traversal()]