How does folding affect the output of JSON from gremlin server? I get different data structure when I unfold and fold path content, it adds the edge and vertex properties. While this is my goal to get the properties in the path as well, but this seems odd behaviour and I could not find about this functionality in the docs.
So why does this happen?
g.V('1').out().path()
g.V('1').out().path().by(unfold().fold())
When I run following query: g.V('1').out().path()
{
...
{
"@type": "g:Path",
"@value": {
"labels": {
"@type": "g:List",
"@value": [
{
"@type": "g:Set",
"@value": []
},
{
"@type": "g:Set",
"@value": []
}
]
},
"objects": {
"@type": "g:List",
"@value": [
{
"@type": "g:Vertex",
"@value": {
"id": "1",
"label": "USER"
}
},
{
"@type": "g:Vertex",
"@value": {
"id": "2",
"label": "USER"
}
}
]
}
}
}
...
}
But when I g.V('1').out().path().by(unfold().fold())
{
...
{
"@type": "g:Path",
"@value": {
"labels": {
"@type": "g:List",
"@value": [
{
"@type": "g:Set",
"@value": []
},
{
"@type": "g:Set",
"@value": []
}
]
},
"objects": {
"@type": "g:List",
"@value": [
{
"@type": "g:List",
"@value": [
{
"@type": "g:Vertex",
"@value": {
"id": "1",
"label": "USER",
"properties": {
"prop1": [
{
"@type": "g:VertexProperty",
"@value": {
"id": {
"@type": "g:Int32",
"@value": 101839172
},
"value": {
"@type": "g:Int32",
"@value": 1
},
"label": "prop1"
}
}
],
"created_at": [
{
"@type": "g:VertexProperty",
"@value": {
"id": {
"@type": "g:Int32",
"@value": 589742877
},
"value": {
"@type": "g:Date",
"@value": 1557226436119
},
"label": "created_at"
}
}
]
}
}
}
]
},
{
"@type": "g:List",
"@value": [
{
"@type": "g:Vertex",
"@value": {
"id": "2",
"label": "USER",
"properties": {
"prop1": [
{
"@type": "g:VertexProperty",
"@value": {
"id": {
"@type": "g:Int32",
"@value": -1354828672
},
"value": {
"@type": "g:Date",
"@value": 1557225020168
},
"label": "prop1"
}
}
],
"created_at": [
{
"@type": "g:VertexProperty",
"@value": {
"id": {
"@type": "g:Int32",
"@value": 589742878
},
"value": {
"@type": "g:Date",
"@value": 1557226436119
},
"label": "created_at"
}
}
]
}
}
}
]
}
]
}
}
}
...
}
EDIT: Additional information, I discovered that additional to fold()
, I can get the whole entity with properties by using project()
and identity()
.
So when I run g.V('1').out().path().by(identity())
I get following contents of a Path, same as first query.
"objects": {
"@type": "g:List",
"@value": [
{
"@type": "g:Vertex",
"@value": {
"id": "1",
"label": "USER"
}
},
{
"@type": "g:Vertex",
"@value": {
"id": "2",
"label": "USER"
}
}
]
}
But when I run g.V('1').out().path().by(project('identity').by(identity()))
, this is what I get in the path(note the properties object):
"objects": {
"@type": "g:List",
"@value": [
{
"@type": "g:Map",
"@value": [
"identity",
{
"@type": "g:Vertex",
"@value": {
"id": "1",
"label": "USER",
"properties": {
"prop1": [
{
"@type": "g:VertexProperty",
"@value": {
"id": {
"@type": "g:Int32",
"@value": 101839172
},
"value": {
"@type": "g:Int32",
"@value": 1
},
"label": "prop1"
}
}
],
"created_at": [
{
"@type": "g:VertexProperty",
"@value": {
"id": {
"@type": "g:Int32",
"@value": 589742877
},
"value": {
"@type": "g:Date",
"@value": 1557226436119
},
"label": "created_at"
}
}
],
}
}
}
]
}