3

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?

tscherg
  • 1,032
  • 8
  • 22

1 Answers1

1

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]))
cybersam
  • 63,203
  • 6
  • 53
  • 76