Skip to content

Commit 171ab93

Browse files
Fix decimal yql nil pointer (#1790)
Co-authored-by: telyatnichenk <[email protected]>
1 parent 4b0c028 commit 171ab93

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

internal/value/value.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"reflect"
99
"sort"
1010
"strconv"
11+
"strings"
1112
"time"
1213

1314
"github.com/google/uuid"
@@ -625,6 +626,9 @@ func (v *decimalValue) Yql() string {
625626
buffer.WriteByte('(')
626627
buffer.WriteByte('"')
627628
s := decimal.FromBytes(v.value[:], v.innerType.Precision(), v.innerType.Scale()).String()
629+
if len(s) < int(v.innerType.Scale()) {
630+
s = strings.Repeat("0", int(v.innerType.Scale())-len(s)) + s
631+
}
628632
buffer.WriteString(s[:len(s)-int(v.innerType.Scale())] + "." + s[len(s)-int(v.innerType.Scale()):])
629633
buffer.WriteByte('"')
630634
buffer.WriteByte(',')

internal/value/value_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ func TestValueYql(t *testing.T) {
505505
value: DecimalValueFromBigInt(big.NewInt(-1234567890123456), 22, 9),
506506
literal: `Decimal("-1234567.890123456",22,9)`,
507507
},
508+
{
509+
value: DecimalValueFromBigInt(big.NewInt(12345678), 22, 9),
510+
literal: `Decimal(".012345678",22,9)`,
511+
},
508512
{
509513
value: DyNumberValue("-1234567890123456"),
510514
literal: `DyNumber("-1234567890123456")`,

0 commit comments

Comments
 (0)