Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace *big.Rat with shopspring decimal.Decimal #1491

Merged
merged 2 commits into from
Mar 16, 2024
Merged

Replace *big.Rat with shopspring decimal.Decimal #1491

merged 2 commits into from
Mar 16, 2024

Conversation

serprex
Copy link
Contributor

@serprex serprex commented Mar 16, 2024

Rational numbers are awkward decimals,
using a decimal type for decimal data has a few benefits:

  1. perf-wise decimal representation is a *big.Int & an int32 exponent (same as pgtype.Numeric), instead of 2 *big.Ints
  2. decimal has obvious conversion to/from decimal strings,
    whereas *big.Rat can be wonky going through FloatString
  3. with scripting most people will want to use their decimal values as decimals, not decimal rationals

A side effect of this is that we now convert NaN/inf/-inf numerics to null. Previously they'd all get converted to NaN. This would only be usable for pg<->pg, only causing trouble with other peers, & even then we'd want inf/-inf to be properly translated

Fixes #1175

@serprex serprex force-pushed the rat-poison branch 8 times, most recently from 45fe520 to d874a66 Compare March 16, 2024 06:18
Copy link
Contributor

@Amogh-Bharadwaj Amogh-Bharadwaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once tests pass

Rational numbers are awkward decimals,
using a decimal type for decimal data has a few benefits:
1. perf-wise decimal representation is a *big.Int & an int32 exponent, instead of 2 *big.Ints
2. decimal has obvious conversion to/from decimal strings, whereas *big.Rat can be wonky going through FloatString
3. with scripting most people will want to use their decimal values as decimals, not decimal rationals

Fixes #1175
@serprex serprex merged commit 1110158 into main Mar 16, 2024
7 checks passed
@serprex serprex deleted the rat-poison branch March 16, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Numeric data type: handle it in Go and Avro as string instead of big.Rat
2 participants