go-zetasqlite icon indicating copy to clipboard operation
go-zetasqlite copied to clipboard

Implement unary minus operator

Open totem3 opened this issue 10 months ago • 0 comments

This Pull Request closes https://github.com/goccy/bigquery-emulator/issues/217

I added a unary minus operator because it was not implemented before. As tested here, It seems to work fine with number literals, but using - on columns causes an error as described in the linked issue.

In this PR, I implemented the unary minus operator. It is basically the same as the SAFE_NEGATE function, as shown in the link below. What different is, an exception occurs when there's an overflow. https://cloud.google.com/bigquery/docs/reference/standard-sql/mathematical_functions#safe_negate

out of scope

This unary minus operator implementation uses SAFE_NEGATE inside, but do not change SAFE_NEGATE behaviour. Currently, SAFE_NEGATE has some incompatibilities. For example,

  • Given math.MinInt64, it returns an unexpected value on ubuntu. (expected 9223372036854775807 but returns -9223372036854775808)
  • Given NaN, NaN is expected but it returns nil
  • Given a large BigNumeric, it returns an unexpected value.

totem3 avatar Apr 10 '24 01:04 totem3