Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

Want better error handling in apoc.number.parseFloat()

Graph Steward

I was trying to do a CSV import and I had a stray extra space at the end of my column name. So, it became the equivalent of:

LOAD CSV WITH HEADERS FROM "file:///import.txt" AS row
apoc.number.parseFloat(row.NonExistantFieldName) AS NonExistantFieldName
RETURN NonExistantFieldName

Failed to invoke function apoc.number.parseFloat: Caused by: java.lang.NullPointerException (Failure when processing file '[directory omitted]/import.txt' on line 2.)

But if I replace function apoc.number.parseFloat() with toFloat(), I get all null values instead of an exception being thrown. While at first glance, the null is a bit mysterious, at least it's not making me wonder if the first string has some mysterious value that is causing the function apoc.number.parseFloat to give up in an unexpected way.

Or even more simple way to cause this error:
match(n) return apoc.number.parseFloat(n.NonExistantFieldName)

Perhaps apoc.number.parseFloat() should return null to be consistent with toFloat()


Graph Fellow

You're right.
To be consistent also with ParseError case (for example apoc.number.parseFloat('aaa')),
with null argument should be return null.
I've created an issue for this one: