With statement in apoc is failing

Please can you help me and a friend of mine. I think this is pretty easy but.. i can't seem to get this to work (sound familiar :slight_smile: )..

I Have This APOC Script:
CALL apoc.load.directory('*.csv','', {recursive: false})
YIELD value WITH value as url ORDER BY url DESC
CALL apoc.load.csv(url, {header:true, results:['map']}) YIELD map AS data1 WITH data1,
apoc.map.mget(data1, ["Label"]) as l1
CALL apoc.merge.node(l1, {prop:apoc.map.values(data1, keys(data1))})
YIELD node AS baseline

WITH baseline
CALL
apoc.load.directory('*.csv','file:///Users/mpare/Library/Application%20Support/Neo4j%20Desktop/Application/relate-data/dbmss/dbms-900521f2-9be2-4824-bd74-33f8cb998712/import/relationships', {recursive: false})
YIELD value WITH value as url1 ORDER BY url1 DESC
CALL apoc.load.csv(url1, {header:true, results:['map']}) YIELD map AS data WITH data

RETURN data, data.Node1, data.Dir1, data.Relationship, data.Dir2, data.Node2

The Question:
all these sections work just fine by themselves. But. put them together and Death.. the WITH baseline fails.. and.. I cannot seem to add this baseline variable into my other With clauses later.. it seems to fall out of scope after the yield completes (which to me seems Nuts).. certainly I cannot finish with a Return that contains baseline.. sigh... what stupid mistake am I making/missing.. ?? Load.directory, destroys previous scopes? should I slam in a match statement? ??

Thanks you again for your patience and kindness.. thanks guys!

baseline is not used in the second part of the query. What final result are you looking for? Do you need to return the node after it is created?

The second part of your query does not mutate the database at all. All you are doing is reading csv files and returning their content. What is the outcome you want with this block of code?

we would like to have it in the last statement.. in the return.. I am thinking that. the apoc.load.csv(url1, {header:true, results:['map']}) YIELD map AS data WITH data removes everything from scope and so.. what we should do is.. put a subquery in there and just get it for later use.. The "With" is not going to work because it is no longer in the game.. you know.. so.. go and re-get it with a merge or match or. whatever.. I will play with this some more tonight.. thanks Gary! Thanks man..

You are correct....You lost it because it went out of scope following the next "with" that did not include it. This would be "with value". You need to keep passing it to have it remain in scope.

You can also use "call subqueries" gather results and have their results appending to the results of the outer query.

Let's get more focused query, or provide more clear result objectives, and I will be happy to help you figure out an approach.

I am assuming you are fully rested from lots of sleep.

@rlukas


It is important to note that WITH affects variables in scope. Any variables not included
 in the WITH clause are not carried over to the rest of the query. The wildcard * can
 be used to include all variables that are currently in scope.
1 Like

correct.. i think we fixed this with subqueries.. need to get with my group and confirm that.. thanks guy.. thanks