0

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?

Matthias
  • 15
  • 3
  • Welcome to Stackoverflow. Please edit your question to clarify your problem description. This might create some more interest. For guidance please check the [how to ask](https://stackoverflow.com/help/how-to-ask) page and [how to create a minimal example](https://stackoverflow.com/help/mcve) page – 5th Sep 10 '18 at 14:30

2 Answers2

1

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]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
0

If you want to get a valueMap with original property values overwritten by the localized properties (if they exist):

g.V().has('name','BananaShop').as('b').
  coalesce(out('FR-FR'), identity()).valueMap().as('l').
  select('b').properties().as('p').
  group().
    by(key()).
    by(coalesce(select('l').select(select('p').key()).unfold(), value()).fold())

Examples

Existing translation

gremlin> g.V().has('name','BananaShop').as('b').
......1>   coalesce(out('FR-FR'), identity()).valueMap().as('l').
......2>   select('b').properties().as('p').
......3>   group().
......4>     by(key()).
......5>     by(coalesce(select('l').select(select('p').key()).unfold(), value()).fold()).
......6>   unfold()
==>bar=[xyz]
==>fuu=[abc]
==>name=[FR.BananaShop]
==>description=[Et ea rebum ...]
==>id=[b3bd8a03-531f-4f7f-b355-32954b03fd21]

Non-existent translation

gremlin> g.V().has('name','BananaShop').as('b').
......1>   coalesce(out('DE-DE'), identity()).valueMap().as('l').
......2>   select('b').properties().as('p').
......3>   group().
......4>     by(key()).
......5>     by(coalesce(select('l').select(select('p').key()).unfold(), value()).fold()).
......6>   unfold()
==>bar=[xyz]
==>fuu=[abc]
==>name=[BananaShop]
==>description=[Ipsum dolor sit ...]
==>id=[fb864e1f-a2e0-4c02-b891-2c0713b29751]
Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34