-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
@@ -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)) |
There was a problem hiding this comment.
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.
apd.Decimal
for DecodeDecimal
apd.Decimal
from DecodeDecimal
@@ -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")), |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
Because
DecodeDecimal
is usingbig.Float
there are small discrepancies with decoding certain numbers. For example, decoding the binary representation of-74961544796695.89960242
produces-74961544796695.89960241
.