vectordotdev/vector

Function to_float fails to parse "0": Invalid float "0": not a normal f64 number

Closed this issue ยท 2 comments

A note for the community

  • Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Problem

When using to_float on a zero (either "0", "0.0", "0.000", ...), parsing fails with:

error[E000]: function call error for "to_float" at (142:156): NaN number not supported "Invalid float \"0\": not a normal f64 number"
  โ”Œโ”€ :4:8
  โ”‚
4 โ”‚ test = to_float!("0")
  โ”‚        ^^^^^^^^^^^^^^ NaN number not supported "Invalid float \"0\": not a normal f64 number"
  โ”‚
  = see language documentation at https://vrl.dev
  = try your code in the VRL REPL, learn more at https://vrl.dev/examples

This issue was introduced in newly released 0.43.0.

Configuration

No response

Version

vector 0.43.0 (aarch64-apple-darwin 88e017f 2024-12-03 22:44:54.502541095)

Debug Output

No response

Example Data

    "one": "1",
    "zero": "0",
    "nan": "nan"
}

.zero_float, .zero_float_err = to_float(.zero)
.one_float, .one_float_err = to_float(.one)
.nan_float, .nan_float_err = to_float(.nan)

{
	"nan": "nan",
	"nan_float": 0,
	"nan_float_err": "function call error for \"to_float\" at (120:134): NaN number not supported \"Invalid float \\\"nan\\\": not a normal f64 number\"",
	"one": "1",
	"one_float": 1,
	"one_float_err": null,
	"zero": "0",
	"zero_float": 0,
	"zero_float_err": "function call error for \"to_float\" at (31:46): NaN number not supported \"Invalid float \\\"0\\\": not a normal f64 number\""
}

Additional Context

https://playground.vrl.dev/?state=eyJwcm9ncmFtIjoiLnplcm9fZmxvYXQsIC56ZXJvX2Zsb2F0X2VyciA9IHRvX2Zsb2F0KC56ZXJvKVxuLm9uZV9mbG9hdCwgLm9uZV9mbG9hdF9lcnIgPSB0b19mbG9hdCgub25lKVxuLm5hbl9mbG9hdCwgLm5hbl9mbG9hdF9lcnIgPSB0b19mbG9hdCgubmFuKVxuIiwiZXZlbnQiOnsib25lIjoiMSIsInplcm8iOiIwIiwibmFuIjoibmFuIn0sImlzX2pzb25sIjpmYWxzZSwiZXJyb3IiOm51bGx9

References

vectordotdev/vrl#1107

pront commented

Thanks for the report @PetrHeinz.

As an immediate workaround you can use parse_float, see example.

We will discuss internally about the proper fix, probably checking for is_normal here is too restrictive.