Skip to content

Commit

Permalink
Kill precision and scale
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Jun 27, 2024
1 parent 91733cb commit 401517e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
8 changes: 4 additions & 4 deletions lib/debezium/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ func TestField_DecodeDecimal(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, testCase.expectedValue, dec.String(), testCase.name)

assert.Equal(t, testCase.expectedPrecision, dec.Precision(), testCase.name)
assert.Equal(t, testCase.expectedScale, dec.Scale(), testCase.name)
assert.Equal(t, testCase.expectedPrecision, dec.Details().Precision(), testCase.name)
assert.Equal(t, testCase.expectedScale, dec.Details().Scale(), testCase.name)
}
}

Expand Down Expand Up @@ -695,8 +695,8 @@ func TestField_DecodeDebeziumVariableDecimal(t *testing.T) {
continue
}

assert.Equal(t, int32(-1), dec.Precision(), testCase.name)
assert.Equal(t, testCase.expectedScale, dec.Scale(), testCase.name)
assert.Equal(t, int32(-1), dec.Details().Precision(), testCase.name)
assert.Equal(t, testCase.expectedScale, dec.Details().Scale(), testCase.name)
assert.Equal(t, testCase.expectedValue, dec.String(), testCase.name)
}

Expand Down
10 changes: 1 addition & 9 deletions lib/typing/decimal/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ func NewDecimal(value *apd.Decimal) *Decimal {
return NewDecimalWithPrecision(value, PrecisionNotSpecified)
}

func (d *Decimal) Scale() int32 {
return -d.value.Exponent
}

func (d *Decimal) Precision() int32 {
return d.precision
}

func (d *Decimal) Value() *apd.Decimal {
return d.value
}
Expand All @@ -43,5 +35,5 @@ func (d *Decimal) String() string {
}

func (d *Decimal) Details() Details {
return NewDetails(d.precision, d.Scale())
return NewDetails(d.precision, -d.value.Exponent)
}
10 changes: 0 additions & 10 deletions lib/typing/decimal/decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ func TestNewDecimalWithPrecision(t *testing.T) {
assert.Equal(t, Details{scale: 2, precision: 4}, NewDecimalWithPrecision(numbers.MustParseDecimal("12.34"), 4).Details())
}

func TestDecimal_Scale(t *testing.T) {
assert.Equal(t, int32(0), NewDecimal(numbers.MustParseDecimal("0")).Scale())
assert.Equal(t, int32(0), NewDecimal(numbers.MustParseDecimal("12345")).Scale())
assert.Equal(t, int32(0), NewDecimal(numbers.MustParseDecimal("12300")).Scale())
assert.Equal(t, int32(1), NewDecimal(numbers.MustParseDecimal("12300.0")).Scale())
assert.Equal(t, int32(2), NewDecimal(numbers.MustParseDecimal("12300.00")).Scale())
assert.Equal(t, int32(2), NewDecimal(numbers.MustParseDecimal("12345.12")).Scale())
assert.Equal(t, int32(3), NewDecimal(numbers.MustParseDecimal("-12345.123")).Scale())
}

func TestDecimal_Details(t *testing.T) {
// -1 precision (PrecisionNotSpecified):
assert.Equal(t, Details{scale: 0, precision: -1}, NewDecimal(numbers.MustParseDecimal("0")).Details())
Expand Down

0 comments on commit 401517e

Please sign in to comment.