Coalesce with Constant
See original GitHub issueHi, I have a problem with projecting connected vertexes. I would like to receive Tuple that contains information regarding ‘Team’ and ‘Stadium’ so this is the query that i’m currently working on :
Gremlin
.V<Team>()
.Project(t => t
.ToTuple()
.By(t => t.Cast<Team>())
.By(__ =>
{
return __.Cast<Stadium>().In<PlaysOn>().OfType<Stadium>()
}));
This works fine when there is data for both Team and Stadium. Problem is when there is no corresponding data for Stadium. I am receiving this information:
Gremlin Query Execution Error: Project By: Next: The provided traverser of key “Item2” maps to nothing.
I thought that in case when there is no corresponding ‘Stadium’, constant of null could help, but i am not able build write ‘Coalesce’ with ‘Constant’. Here is how i would imagine it (code not compiling) :
Gremlin
.V<Team>()
.Project(t => t
.ToTuple()
.By(t => t.Cast<Team>())
.By(__ =>
{
return __.In<PlaysOn>().OfType<Stadium>().Fold().Coalesce(
_ => _.Unfold(),
_ => _.Constant<Stadium>(null));
}));
Here is the query that works on gremlin
g.V()
.hasLabel('Team').as('T')
.project('team', 'stadium')
.by(select('T'))
.by(__.in('PlaysOn').has('label', 'Stadium').fold().coalesce(
unfold(), constant('No Stadium')))
I tried to use Constant in different ways but i was not able to make it work. Could you also give some simple example how this should look like?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Slip a ForceValue() in before the casts. Currently, one is a IValue… and the other is a IVertex…ForceValue will make the interfaces equal.
Actually, why even do the whole Coalesce-thingy. If you change the view on the domain such that teams may have 0-n stadiums, a single Fold() will do.
Thank you, both solutions are working