neo4j-jdbc
neo4j-jdbc copied to clipboard
error related to Cypher + CASE + null (note, not a general cypher issue, only occurs with JDBC)
Firstly, note, the following error does not exist when using Embedded Cypher (without JDBC driver) for any version between 2.0.0-2.1.4, all of them return the correct result with this exact query. I have tried the same query with the two latest JDBC driver versions, 2.0.2 and 2.1.4, and the bug is present in both of them.
The query is:
MATCH (person1:Person {id:{person1Id}}), (person2:Person {id:{person2Id}}) OPTIONAL MATCH path = shortestPath((person1)-[:KNOWS]-(person2)) RETURN CASE path IS NULL WHEN true THEN -1 ELSE length(path) END AS pathLength
When run on this test graph:
CREATE (p0:Person {id:0}), (p1:Person {id:1}), (p2:Person {id:2}), (p3:Person {id:3}), (p4:Person {id:4}), (p5:Person {id:5}), (p6:Person {id:6}), (p7:Person {id:7}), (p8:Person {id:8}), (p0)-[:KNOWS]->(p1), (p1)-[:KNOWS]->(p3), (p1)<-[:KNOWS]-(p2), (p3)-[:KNOWS]->(p2), (p2)<-[:KNOWS]-(p4), (p4)-[:KNOWS]->(p7), (p4)-[:KNOWS]->(p6), (p6)<-[:KNOWS]-(p5)
Using these parameters:
{person1Id=1, person2Id=8}
There should be no path between the two nodes, and therefore the result should be -1. However, when using the JDBC driver the result is 0 instead.
The problem is that Cypher computes -1 as Long
value in the result and the default implementation of the Neo4j driver returned 0 on all Objects that were not Integer
instances on getInt()
try to use getLong() as a workaround or ((Number)getObject(x)).intValue()