-
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
Changes from 26 commits
e133873
64f6bca
97d4da3
f6bbb16
b9baad6
19a13f6
14e5e04
77f2451
1d5d48f
9162e2f
c1bd606
55c4ace
db1a91b
47489e7
e02f40f
aee754d
f6f1fee
48d8648
a487eba
e9413f4
7b9ef83
8ba46d9
fab0b1b
4b3327c
8ab7bf0
8ca4bcc
b41c61e
f23b0a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,9 +65,11 @@ func TestDecimalWithNewExponent(t *testing.T) { | |
func TestEncodeDecimal(t *testing.T) { | ||
testEncodeDecimal := func(value string, expectedScale int32) { | ||
bytes, scale := EncodeDecimal(numbers.MustParseDecimal(value)) | ||
actual := DecodeDecimal(bytes, nil, int(scale)).String() | ||
assert.Equal(t, value, actual, value) | ||
assert.Equal(t, expectedScale, scale, value) | ||
|
||
actual := DecodeDecimal(bytes, scale) | ||
assert.Equal(t, value, actual.Text('f'), value) | ||
assert.Equal(t, expectedScale, -actual.Exponent, value) | ||
} | ||
|
||
testEncodeDecimal("0", 0) | ||
|
@@ -85,7 +87,7 @@ func TestEncodeDecimal(t *testing.T) { | |
func TestEncodeDecimalWithScale(t *testing.T) { | ||
mustEncodeAndDecodeDecimal := func(value string, scale int32) string { | ||
bytes := EncodeDecimalWithScale(numbers.MustParseDecimal(value), scale) | ||
return DecodeDecimal(bytes, nil, int(scale)).String() | ||
return DecodeDecimal(bytes, scale).String() | ||
} | ||
|
||
// Whole numbers: | ||
|
@@ -125,6 +127,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 commentThe reason will be displayed to describe this comment to others. Learn more. This test fails on master. |
||
|
||
testCases := []struct { | ||
name string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This was decoding incorrectly, the unscaled value is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which makes sense since this number is just |
||
require.NoError(b, err) | ||
} | ||
} | ||
|
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.