Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypher query to dynamically match parameter in apoc call

I am using a query of the following structure

MATCH path=((:Start)-[:NEXT*..100]->(n))
WHERE ALL(mnode IN nodes(path)
    WHERE mnode.minimum <= $data[mnode.checkagainst])

where data is something like {checkparam1: 24}. What this does for me is: the name of the parameter against which I want to check the minimum resides in the node.

All is working fine, however when I build in apoc stuff like

MATCH path=((:Start)-[:NEXT*..100]->(n))
WHERE ALL(mnode IN nodes(path)
    WHERE mnode.minimum <= apoc.date.toYear($data[mnode.checkagainst]))

it tells me

Failed to invoke function `apoc.date.toYears`: Caused by: java.lang.NullPointerException

I suspect that I can't rely on "information from the query memory" inside the apoc call, because when I manually fill in the value of mnode.checkagainst like

MATCH path=((:Start)-[:NEXT*..100]->(n))
WHERE ALL(mnode IN nodes(path)
    WHERE mnode.minimum <= apoc.date.toYear($data['checkparam1']))

the apoc call works. Not sure whether this is intended behaviour?

Any suggestions for a workaround?

like image 337
tscherg Avatar asked Jan 25 '26 15:01

tscherg


1 Answers

The apoc.date.toYear($data[mnode.checkagainst]) call will produce that error if any mnode is missing the checkagainst property.

The following (partial) query should produce only paths in which all nodes have the checkagainst property (and pass the <= test):

MATCH path=((:Start)-[:NEXT*..100]->(n))
WHERE ALL(mnode IN nodes(path)
  WHERE
    mnode.checkagainst IS NOT NULL &&
    mnode.minimum <= apoc.date.toYears($data[mnode.checkagainst]))
like image 190
cybersam Avatar answered Jan 27 '26 07:01

cybersam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!