cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

RETURN: excluding table lines with empty properties

guido
Graph Buddy

Probably a typical newby question :-)...
I have created the following table:

MATCH (s:Source)
WHERE s.title = $neodash_source_title  //  value comes from a parameter select function
WITH s LIMIT 1
MATCH (s:Source)-[r:PRODUCED_BY ]->(p:Producer)-[v:HAS_NAME_VARIANT {qualification: "preferred"}]->(n:Name)
WITH [ "Subtitle: " + s.subtitle,
             "Year: " + s.year,
             "Author: " + n.text,
             "ISBN: " + s.ISBN
] as data
UNWIND data as Information
RETURN Information

If e.g. the property "ISBN" is empty, how can I suppress the whole line  "ISBN: " + s.ISBN ?
isEmpty will leave the value empty, but "ISBN: " will still appear.

Thanks for any help!

1 ACCEPTED SOLUTION

This should work for empty strings, as a replacement for line 10 that filtered on null values. 

WITH [i in allData where not i ends with ': '] as data

 

View solution in original post

8 REPLIES 8

Try this.  It filters out the elements in your data list that have a size equal to zero. These should be the elements that have properties that are null (don't exists), as "a constant string" + null = null.

MATCH (s:Source)
WHERE s.title = $neodash_source_title  //  value comes from a parameter select function
WITH s LIMIT 1
MATCH (s:Source)-[r:PRODUCED_BY ]->(p:Producer)-[v:HAS_NAME_VARIANT {qualification: "preferred"}]->(n:Name)
WITH [ "Subtitle: " + s.subtitle,
             "Year: " + s.year,
             "Author: " + n.text,
             "ISBN: " + s.ISBN
] as allData
WITH [i in allData where size(i)>0] as data
UNWIND data as Information
RETURN Information

 

guido
Graph Buddy

@ glilienfield
Thank you for your suggestion. Unfortunately, the lines with null values still appear, see "ISBN" and "Subtitle":Schermafdruk 2022-07-03 15.46.05.png 

Hi @guido !

Thanks for using NeoDash! About your query, looks like you have some empty strings as properties. Can you confirm this theory? In that case, removing empty string properties will improve your model while also reducing a bit your disk usage.

Bennu

Oh, y’all wanted a twist, ey?

Are the empty strings vs. null values? 

This should work for empty strings, as a replacement for line 10 that filtered on null values. 

WITH [i in allData where not i ends with ': '] as data

 

Ingenius solution, thank you!

Sorry, I meant: empty strings

guido
Graph Buddy

Hello @bennu_neo ,
That seems to do the trick.
The empty strings are created by data-importer.neo4j.io  Is there a way to prevent it from creating these NULLs? Thank you.