question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coalesce with Constant

See original GitHub issue

Hi, 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
danielcwebercommented, Feb 27, 2021

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.

0reactions
BlaszczykBcommented, Mar 2, 2021

Thank you, both solutions are working

Read more comments on GitHub >

github_iconTop Results From Across the Web

COALESCE function is not working when I pass NULL ...
I think the error is pretty clear: coalesce() "needs" a non-constant argument that is not NULL . So, the grammar has imposed a...
Read more >
Fix “At least one of the arguments to COALESCE must be ...
Fix “At least one of the arguments to COALESCE must be an expression that is not the NULL constant” in SQL Server.
Read more >
COALESCE() SQL Function
Example 1: COALESCE() a column with a constant​​ Consider the table countries with a list of countries and their national days. Some national...
Read more >
Using the SQL Coalesce function in SQL Server
The SQL Coalesce and IsNull functions are used to handle NULL values. During the expression evaluation process the NULL values are replaced with ......
Read more >
COALESCE Function - SAS Help Center
The COALESCE function checks the value of each argument in the order in which they are listed and returns the first nonmissing value....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found