List only nodes that have values along with their relationships for a Cypher query

I am executing Cypher queries in Neo4j browser
I have created multiple nodes and relationships between them
MATCH p=()-->() RETURN p - using this query to return all nodes and relationships

My csv file is placed in azure datalake and use LOAD CSV command by generating SAS URL

LOAD CSV WITH HEADERS FROM '<https://SAS URL>' AS row
MERGE (n:Person {name:row.Person})
MERGE (t:Test1 {name:row.Test1})
MERGE (te:Test2 {name:row.Test2})
MERGE (l:Test1_Location {name:row.Test1_Location})
MERGE (lo:Test2_Location {name:row.Test2_Location})

MATCH (n:Person {name:row.Person})
MATCH (t:Test1 {name:row.Test1})
MATCH (te:Test2 {name:row.Test2})
MATCH (l:Test1_Location {name:row.Test1_Location})
MATCH (lo:Test2_Location {name:row.Test2_Location})

MERGE (n)-[:RESPONDED_FOR]->(t)
MERGE (n)-[:RESPONDED_FOR]->(te)
MERGE (t)-[:CONDUCTED_IN]->(l)
MERGE (te)-[:CONDUCTED_IN]->(lo)

I have a Person node in the middle that is related to Test1 and Test2
There are separate attributes for Test1 and Test2

I have two rows in my test csv file
First row has all details for Test1 and Test2
Second row has only details for Test1 (no details for Test2)

When I try to view all nodes and relationships using "MATCH p=()-->() RETURN p"
I am getting blank nodes in place where there are no details for Test2 ( as shown in image2)

I need to get result as below:
when all values are present, show all nodes and relations
if test2 values are not present in the file, I want to show only Test1 values related to Person, no test2 nodes/relationships should be viewed

Please suggest any option to tweak my cypher query to get the above result.




image

Try this

LOAD CSV WITH HEADERS FROM '<https://SAS URL>' AS row

MERGE (n:Person {name:row.Person})
MERGE (t:Test1 {name:row.Test1})
MERGE (n)-[:RESPONDED_FOR]->(t)
MERGE (l:Test1_Location {name:row.Test1_Location})
MERGE (t)-[:CONDUCTED_IN]->(l)

WITH n, row

FOREACH(ignoreMe IN CASE WHEN row.Test2 is not null THEN [1] ELSE END|

MERGE (te:Test2 {name:row.Test2})

MERGE (lo:Test2_Location {name:row.Test2_Location})
MERGE (n)-[:RESPONDED_FOR]->(te)
MERGE (te)-[:CONDUCTED_IN]->(lo)

)

and run your MATCH p=()-->() RETURN p query and your should see your expected output.

I am getting this error.
whats this END| -- is this pipeline at the end?

Invalid input '|': expected an identifier character, whitespace, '{', node labels, a property map, a relationship pattern, '.', '(', '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR or END (line 9, column 71 (offset: 263))
"FOREACH(ignoreMe IN CASE WHEN row.Test2 is not null THEN [1] ELSE END|"
^

FOREACH(ignoreMe IN CASE WHEN row.Test2 is not null THEN [1] ELSE END|

After ELSE it is two square brackets: opening and closing. Here it displays like a box.

Check this link:

The pipe here is used as a separator between the iteration part of the FOREACH, and the subsequent Cypher to execute per list element. Though usually there's a space before the separator, it shouldn't be a syntax error.

This is working when I check for
FOREACH(ignoreMe IN CASE WHEN row.Test2 contains "Test" THEN [1] ELSE END|

NOT NULL is not working
Ideally, the column has no value, can it be checked for spaces or blanks like
FOREACH(ignoreMe IN CASE WHEN row.Test2 is not blank THEN [1] ELSE END|
or
FOREACH(ignoreMe IN CASE WHEN row.Test2 is not spaces THEN [1] ELSE END|

Try this:

FOREACH(ignoreMe IN CASE WHEN row.Test2 <> ' ' or row.Test2 is not null THEN [1] ELSE END|