arrow icon indicating copy to clipboard operation
arrow copied to clipboard

[C++] Allow `NaN`, `Infinity`, `-Infinity` as json values

Open taepper opened this issue 1 month ago • 3 comments

Describe the enhancement requested

Follow-up to #51038 (replacing RapidJSON json parser with a simdjson based implementation)

The RapidJSON parser used kParseNanAndInfFlag, allowing non-standard float literals such as NaN, Infinity and -Infinity. With simdjson 4.x these values are reported as json_type::unknown (we raise them with "Invalid JSON value").

simdjson 5.0 supports NaN, Inf and similar spellings. Once Arrow bumps to simdjson >= 5 (currently pinned to < 5, see related issues #51690, #51809), we should restore support for these values in the JSON parser by setting the respective flag in simdjson.

Component(s)

C++ (, Python? since this is visible for pyarrow consumers)

taepper avatar Oct 06 '26 09:10 taepper

We should build simdjson ourselves to enable this ? i think its a cmake option and the default is OFF. or maybe give to some converter (parser) ?

imtherealnaska avatar Oct 08 '26 13:10 imtherealnaska

We should build simdjson ourselves to enable this ? i think its a cmake option and the default is OFF. or maybe give to some converter (parser) ?

Yes, this is in the body of the issue :) Note that the flag is only available since simdjson 5.0. We are currently still on version 4

taepper avatar Oct 08 '26 13:10 taepper

To enable the cmake option:

Users can opt-in to parsing Infinity, -Infinity, and NaN as double values by setting the SIMDJSON_ENABLE_NAN_INF flag to ON when building simdjson: cmake -B build -D SIMDJSON_ENABLE_NAN_INF=ON and setting SIMDJSON_ENABLE_NAN_INF to 1 before including "simdjson.h". When enabled, Infinity, -Infinity, Inf, -Inf, and NaN literals are case-insensitively matched and parsed as double: https://github.com/simdjson/simdjson/blob/master/doc/basics.md#infinity-and-nan-support

taepper avatar Oct 08 '26 14:10 taepper