RedisGraph icon indicating copy to clipboard operation
RedisGraph copied to clipboard

Incorrect result when comparing to NaN value

Open InverseIntegral opened this issue 2 years ago • 4 comments

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

InverseIntegral avatar Jun 27 '22 23:06 InverseIntegral

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

AviAvni avatar Jun 30 '22 08:06 AviAvni

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

InverseIntegral avatar Jun 30 '22 12:06 InverseIntegral

so the expectation is not for the count to be 1 is to return false

AviAvni avatar Jul 04 '22 08:07 AviAvni

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'

InverseIntegral avatar Jul 04 '22 09:07 InverseIntegral

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

LiorKogan avatar Oct 31 '22 18:10 LiorKogan

It seems like Neo4J implemented it according to the IEEE 754 floating-point standard

InverseIntegral avatar Nov 01 '22 19:11 InverseIntegral