Skip to content

Commit 4746449

Browse files
committed
refactor: rename ScaledDecimal to Decimal for consistency across the codebase
1 parent 0f8349b commit 4746449

File tree

8 files changed

+33
-33
lines changed

8 files changed

+33
-33
lines changed

buffer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func (b *buffer) Float64Column(name string, val float64) *buffer {
573573
return b
574574
}
575575

576-
func (b *buffer) DecimalColumn(name string, val ScaledDecimal) *buffer {
576+
func (b *buffer) DecimalColumn(name string, val Decimal) *buffer {
577577
if val.isNull() {
578578
// Don't write null decimals
579579
return b
@@ -584,7 +584,7 @@ func (b *buffer) DecimalColumn(name string, val ScaledDecimal) *buffer {
584584
return b.decimalColumn(name, val)
585585
}
586586

587-
func (b *buffer) decimalColumn(name string, val ScaledDecimal) *buffer {
587+
func (b *buffer) decimalColumn(name string, val Decimal) *buffer {
588588
if err := val.ensureValidScale(); err != nil {
589589
b.lastErr = err
590590
return b

buffer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ func TestDecimalColumn(t *testing.T) {
501501
prefix := []byte(testTable + " price==")
502502
testCases := []struct {
503503
name string
504-
value qdb.ScaledDecimal
504+
value qdb.Decimal
505505
expected []byte
506506
}{
507507
{
@@ -536,7 +536,7 @@ func TestDecimalColumnTrimmingAndPadding(t *testing.T) {
536536

537537
testCases := []struct {
538538
name string
539-
value qdb.ScaledDecimal
539+
value qdb.Decimal
540540
expectedBytes []byte
541541
}{
542542
{

decimal.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ const (
3535
maxDecimalScale uint32 = 76
3636
)
3737

38-
// ScaledDecimal represents a decimal value as a two's complement big-endian byte slice and a scale.
39-
// NULL decimals are represented by an offset of 32.
40-
type ScaledDecimal struct {
38+
// Decimal represents a decimal value as a two's complement big-endian byte slice and a scale.
39+
type Decimal struct {
4140
scale uint32
4241
unscaled [32]byte
4342
offset uint8
@@ -48,19 +47,20 @@ type ShopspringDecimal interface {
4847
Exponent() int32
4948
}
5049

51-
// NewScaledDecimal constructs a decimal from a two's complement big-endian unscaled value and a scale.
50+
// NewDecimalUnsafe constructs a decimal from a two's complement big-endian unscaled value and a scale.
5251
// A nil/empty unscaled slice produces a NULL decimal.
53-
func NewScaledDecimal(unscaled []byte, scale uint32) (ScaledDecimal, error) {
52+
func NewDecimalUnsafe(unscaled []byte, scale uint32) (Decimal, error) {
5453
if len(unscaled) == 0 {
55-
return ScaledDecimal{
54+
// NULL decimals are represented by an offset of 32.
55+
return Decimal{
5656
offset: 32,
5757
}, nil
5858
}
5959
normalized, offset, err := normalizeTwosComplement(unscaled)
6060
if err != nil {
61-
return ScaledDecimal{}, err
61+
return Decimal{}, err
6262
}
63-
return ScaledDecimal{
63+
return Decimal{
6464
scale: scale,
6565
unscaled: normalized,
6666
offset: offset,
@@ -69,43 +69,43 @@ func NewScaledDecimal(unscaled []byte, scale uint32) (ScaledDecimal, error) {
6969

7070
// NewDecimal constructs a decimal from an arbitrary-precision integer and a scale.
7171
// Providing a nil unscaled value produces a NULL decimal.
72-
func NewDecimal(unscaled *big.Int, scale uint32) (ScaledDecimal, error) {
72+
func NewDecimal(unscaled *big.Int, scale uint32) (Decimal, error) {
7373
if unscaled == nil {
74-
return ScaledDecimal{
74+
return Decimal{
7575
offset: 32,
7676
}, nil
7777
}
7878
unscaledRaw, offset, err := bigIntToTwosComplement(unscaled)
7979
if err != nil {
80-
return ScaledDecimal{}, err
80+
return Decimal{}, err
8181
}
82-
return ScaledDecimal{
82+
return Decimal{
8383
scale: scale,
8484
unscaled: unscaledRaw,
8585
offset: offset,
8686
}, nil
8787
}
8888

8989
// NewDecimalFromInt64 constructs a decimal from a 64-bit integer and a scale.
90-
func NewDecimalFromInt64(unscaled int64, scale uint32) ScaledDecimal {
90+
func NewDecimalFromInt64(unscaled int64, scale uint32) Decimal {
9191
var be [8]byte
9292
binary.BigEndian.PutUint64(be[:], uint64(unscaled))
9393
offset := trimTwosComplement(be[:])
9494
payload := [32]byte{}
9595
copy(payload[32-(8-offset):], be[offset:])
96-
return ScaledDecimal{
96+
return Decimal{
9797
scale: scale,
9898
unscaled: payload,
9999
offset: uint8(32 - (8 - offset)),
100100
}
101101
}
102102

103103
// isNull reports whether the decimal represents NULL.
104-
func (d ScaledDecimal) isNull() bool {
104+
func (d Decimal) isNull() bool {
105105
return d.offset >= 32
106106
}
107107

108-
func (d ScaledDecimal) ensureValidScale() error {
108+
func (d Decimal) ensureValidScale() error {
109109
if d.isNull() {
110110
return nil
111111
}
@@ -115,10 +115,10 @@ func (d ScaledDecimal) ensureValidScale() error {
115115
return nil
116116
}
117117

118-
func convertShopspringDecimal(value ShopspringDecimal) (ScaledDecimal, error) {
118+
func convertShopspringDecimal(value ShopspringDecimal) (Decimal, error) {
119119
coeff := value.Coefficient()
120120
if coeff == nil {
121-
return ScaledDecimal{
121+
return Decimal{
122122
offset: 32,
123123
}, nil
124124
}

http_sender.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (s *httpLineSender) DecimalColumnShopspring(name string, val ShopspringDeci
315315
return s
316316
}
317317

318-
func (s *httpLineSender) DecimalColumn(name string, val ScaledDecimal) LineSender {
318+
func (s *httpLineSender) DecimalColumn(name string, val Decimal) LineSender {
319319
s.buf.SetLastErr(errDecimalNotSupported)
320320
return s
321321
}
@@ -662,7 +662,7 @@ func (s *httpLineSenderV2) DecimalColumnShopspring(name string, val ShopspringDe
662662
return s
663663
}
664664

665-
func (s *httpLineSenderV2) DecimalColumn(name string, val ScaledDecimal) LineSender {
665+
func (s *httpLineSenderV2) DecimalColumn(name string, val Decimal) LineSender {
666666
s.buf.SetLastErr(errDecimalNotSupported)
667667
return s
668668
}
@@ -727,7 +727,7 @@ func (s *httpLineSenderV3) Float64ArrayNDColumn(name string, values *NdArray[flo
727727
return s
728728
}
729729

730-
func (s *httpLineSenderV3) DecimalColumn(name string, val ScaledDecimal) LineSender {
730+
func (s *httpLineSenderV3) DecimalColumn(name string, val Decimal) LineSender {
731731
s.buf.DecimalColumn(name, val)
732732
return s
733733
}

interop_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ func execute(t *testing.T, ctx context.Context, sender qdb.LineSender, backCh ch
155155
}
156156

157157
// parseDecimal64 quick and dirty parser for a decimal64 value from its string representation
158-
func parseDecimal64(s string) (qdb.ScaledDecimal, error) {
158+
func parseDecimal64(s string) (qdb.Decimal, error) {
159159
// Remove whitespace
160160
s = strings.TrimSpace(s)
161161

162162
// Check for empty string
163163
if s == "" {
164-
return qdb.ScaledDecimal{}, fmt.Errorf("empty string")
164+
return qdb.Decimal{}, fmt.Errorf("empty string")
165165
}
166166

167167
// Find the decimal point and remove it
@@ -173,7 +173,7 @@ func parseDecimal64(s string) (qdb.ScaledDecimal, error) {
173173
// Parse the integer part
174174
unscaled, err := strconv.ParseInt(s, 10, 64)
175175
if err != nil {
176-
return qdb.ScaledDecimal{}, err
176+
return qdb.Decimal{}, err
177177
}
178178

179179
scale := 0

sender.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ type LineSender interface {
123123
// Column name cannot contain any of the following characters:
124124
// '\n', '\r', '?', '.', ',', ”', '"', '\', '/', ':', ')', '(', '+',
125125
// '-', '*' '%%', '~', or a non-printable char.
126-
DecimalColumn(name string, val ScaledDecimal) LineSender
126+
DecimalColumn(name string, val Decimal) LineSender
127127

128128
// DecimalColumnShopspring adds a decimal column value to the ILP message.
129129
//

sender_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (ps *pooledSender) DecimalColumnShopspring(name string, val ShopspringDecim
324324
return ps
325325
}
326326

327-
func (ps *pooledSender) DecimalColumn(name string, val ScaledDecimal) LineSender {
327+
func (ps *pooledSender) DecimalColumn(name string, val Decimal) LineSender {
328328
ps.wrapped.DecimalColumn(name, val)
329329
return ps
330330
}

tcp_sender.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (s *tcpLineSender) DecimalColumnShopspring(name string, val ShopspringDecim
213213
return s
214214
}
215215

216-
func (s *tcpLineSender) DecimalColumn(name string, val ScaledDecimal) LineSender {
216+
func (s *tcpLineSender) DecimalColumn(name string, val Decimal) LineSender {
217217
s.buf.SetLastErr(errDecimalNotSupported)
218218
return s
219219
}
@@ -391,7 +391,7 @@ func (s *tcpLineSenderV2) DecimalColumnShopspring(name string, val ShopspringDec
391391
return s
392392
}
393393

394-
func (s *tcpLineSenderV2) DecimalColumn(name string, val ScaledDecimal) LineSender {
394+
func (s *tcpLineSenderV2) DecimalColumn(name string, val Decimal) LineSender {
395395
s.buf.SetLastErr(errDecimalNotSupported)
396396
return s
397397
}
@@ -461,7 +461,7 @@ func (s *tcpLineSenderV3) DecimalColumnFromString(name string, val string) LineS
461461
return s
462462
}
463463

464-
func (s *tcpLineSenderV3) DecimalColumn(name string, val ScaledDecimal) LineSender {
464+
func (s *tcpLineSenderV3) DecimalColumn(name string, val Decimal) LineSender {
465465
s.buf.DecimalColumn(name, val)
466466
return s
467467
}

0 commit comments

Comments
 (0)