im working with the Apache gremlin graph and TinkerPop3. There are two nodes
<!-- # parentNode with properties # -->
g.addV('Location')
.property('id', 'fb864e1f-a2e0-4c02-b891-2c0713b29751')
.property('name', 'BananaShop')
.property('description', 'Ipsum dolor sit ...')
.property('fuu', 'abc')
.property('bar', 'xyz')
.addE('FR-FR').to(g.V('b3bd8a03-531f-4f7f-b355-32954b03fd21'))
and also
<!-- # childNode with translations only # -->
g.addV('Localized')
.property('id', 'b3bd8a03-531f-4f7f-b355-32954b03fd21')
.property('name', 'FR.BananaShop')
.property('description', 'Et ea rebum ...')
my query is:
g.V().has("Name","BananaShop").as("a").out("FR-FR").as("b").select("a","b")
The result is fine. I got both nodes, with all properties! But i´m only interested in a singel result with the properties of the parent node and the translations of the child node. if i have no matching child with translations, that select the "name" and "description" of the parent.
{
id : ...,
name : "FR-FR", // childnode data
description : "FR-FR", // childnode data
fuu : "...",
bar : "..."
}
How do i need to change my query for this?
I would use project()
in this case:
gremlin> g.V().has('name','BananaShop').
......1> project('id','name','description','fuu','bar').
......2> by('id').
......3> by(out('FR-FR').values('name')).
......4> by(out('FR-FR').values('description')).
......5> by('fuu').
......6> by('bar')
==>[id:fb864e1f-a2e0-4c02-b891-2c0713b29751,name:FR.BananaShop,description:Et ea rebum ...,fuu:abc,bar:xyz]
You are traversing out()
twice though by doing this. If that is expensive in CosmosDB, you could consider changing your format to something more like:
gremlin> g.V().has('name','BananaShop').
......1> project('id','child','fuu','bar').
......2> by('id').
......3> by(out('FR-FR').project('name','description').by('name').by('description')).
......4> by('fuu').
......5> by('bar')
==>[id:fb864e1f-a2e0-4c02-b891-2c0713b29751,child:[name:FR.BananaShop,description:Et ea rebum ...],fuu:abc,bar:xyz]