RedisGraph
RedisGraph copied to clipboard
Incorrect result when comparing to NaN value
When I run the following queries
CREATE (iJnNiEn:Hx {tp:0/0})
CREATE INDEX FOR (n:Hx) ON (n.tp)
MATCH (n:Hx) RETURN n.tp = 10
MATCH (n:Hx) WHERE n.tp = 10 RETURN COUNT(n)
I get the following result
{n.tp = 10=true}
{COUNT(n)=0}
I would expect the COUNT(n)
to be 1
. This seems to only happen when an index is present.
This issue is similar to #2434. But in this case it seems to happen for NaN vaues instead of an empty string.
Redis Version: 6.2.5 RedisGraph Version: Self built from master branch (02c9cfd66b3281f9bc34914f3522656372ff1b8b) Operating System: 5.18.2 Arch Linux
neo4j don't allow to run CREATE (iJnNiEn:Hx {tp:0/0}) so the fix is is to raise error when a divide by zero happen
Yes you are correct, this would throw an exception in Neo4J. But the following example works on both graph databases:
CREATE (:L {p:0.0/0.0})
CREATE INDEX FOR (n:L) ON (n.p)
MATCH (n:L) RETURN n.p = 10
MATCH (n:L) WHERE n.p = 10 RETURN COUNT(n)
Neo4J outputs:
false
0
but RedisGraph outputs:
true
0
so the expectation is not for the count to be 1 is to return false
Yes you are right, since we compare 10 = NaN
it should be false
. The COUNT(n)
part is actually correct.
In particular, the following queries seem to return incorrect results:
GRAPH.QUERY db 'RETURN 0.0/0.0 = 10'
GRAPH.QUERY db 'RETURN 0.0/0.0 <> 10'
GRAPH.QUERY db 'RETURN 0.0/0.0 <= 10'
GRAPH.QUERY db 'RETURN 0.0/0.0 >= 10'
All comparability tests (<, <=, >, >=) with NaN evaluate as false. For example, 1 > b and 1 < b are both false when b is NaN.
https://neo4j.com/docs/cypher-manual/current/syntax/operators/#cypher-comparison
It seems like Neo4J implemented it according to the IEEE 754 floating-point standard