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

[debezium] Return apd.Decimal from DecodeDecimal #765

Merged
merged 28 commits into from
Jun 26, 2024
Merged

Conversation

nathan-artie
Copy link
Contributor

@nathan-artie nathan-artie commented Jun 26, 2024

Because DecodeDecimal is using big.Float there are small discrepancies with decoding certain numbers. For example, decoding the binary representation of -74961544796695.89960242 produces -74961544796695.89960241.

@@ -132,6 +112,7 @@ func TestEncodeDecimalWithScale(t *testing.T) {
assert.Equal(t, "-145.1830000000000090", mustEncodeAndDecodeDecimal("-145.183000000000009", 16))

assert.Equal(t, "-9063701308.217222135", mustEncodeAndDecodeDecimal("-9063701308.217222135", 9))
assert.Equal(t, "-74961544796695.89960242", mustEncodeAndDecodeDecimal("-74961544796695.89960242", 8))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test fails on master.

@nathan-artie nathan-artie changed the title [debezium] Use apd.Decimal for DecodeDecimal [debezium] Return apd.Decimal from DecodeDecimal Jun 26, 2024
@nathan-artie nathan-artie marked this pull request as draft June 26, 2024 07:03
@@ -129,9 +129,9 @@ func TestRowToMessage(t *testing.T) {
"c_float_int32": int32(1234),
"c_float_int64": int64(1234),
"c_float_string": "4444.55555",
"c_numeric": decimal.NewDecimal(nil, 5, big.NewFloat(3.1415926)),
"c_numeric": decimal.NewDecimal(nil, numbers.MustParseDecimal("3.14159")),
Copy link
Contributor Author

@nathan-artie nathan-artie Jun 26, 2024

Choose a reason for hiding this comment

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

We now rely on the exponent of the decimal instead of passing in a scale, so the decimal places here were trimmed to 5 to match the previous scale.

@@ -19,7 +19,7 @@ func BenchmarkDecodeDecimal_P64_S10(b *testing.B) {
assert.NoError(b, err)
dec, err := field.DecodeDecimal(bytes)
assert.NoError(b, err)
assert.Equal(b, "123456789012345678901234567890123456789012345678901234.1234567889", dec.Value())
assert.Equal(b, "123456789012345678901234567890123456789012345678901234.1234567890", dec.String())
Copy link
Contributor Author

@nathan-artie nathan-artie Jun 26, 2024

Choose a reason for hiding this comment

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

This was decoding incorrectly, the unscaled value is 1234567890123456789012345678901234567890123456789012341234567890

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which makes sense since this number is just 1234567890 repeating (with a 1234 before the decimal point).

@nathan-artie nathan-artie marked this pull request as ready for review June 26, 2024 18:58
@nathan-artie nathan-artie merged commit 9d1f5ab into master Jun 26, 2024
1 check passed
@nathan-artie nathan-artie deleted the nv/use-decimal branch June 26, 2024 21:08
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.

2 participants