Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Moved `internal/decimal` package to `pkg/decimal` for public usage

## v3.122.0
* Added `trace.NodeHintInfo` field for OnPoolGet trace callback which stores info for node hint misses
* Added `ydb_go_sdk_ydb_table_pool_node_hint_miss` and `ydb_go_sdk_ydb_query_pool_node_hint_miss` metrics for node hint misses
Expand All @@ -11,7 +13,7 @@
* Changed internal pprof label to pyroscope supported format
* Added `query.ImplicitTxControl()` transaction control (the same as `query.NoTx()` and `query.EmptyTxControl()`). See more about implicit transactions on [ydb.tech](https://ydb.tech/docs/en/concepts/transactions?version=v25.2#implicit)
* Added `SnapshotReadWrite` isolation mode support to `database/sql` driver using `sql.TxOptions{Isolation: sql.LevelSnapshot, ReadOnly: false}`
* Move `internal/ratelimiter/options` to `ratelimiter/options` for public usage
* Moved `internal/ratelimiter/options` to `ratelimiter/options` for public usage

## v3.120.0
* Added support of `SnapshotReadWrite` isolation mode into query and table clients
Expand Down
86 changes: 0 additions & 86 deletions internal/decimal/decimal_test.go

This file was deleted.

19 changes: 0 additions & 19 deletions internal/decimal/type.go

This file was deleted.

14 changes: 7 additions & 7 deletions internal/query/scanner/struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/stretchr/testify/require"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/xtest"
ttypes "github.com/ydb-platform/ydb-go-sdk/v3/table/types"
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)

func TestFieldName(t *testing.T) {
Expand Down Expand Up @@ -934,9 +934,9 @@ func TestScannerDecimal(t *testing.T) {
},
))
var row struct {
A ttypes.Decimal
A types.Decimal
}
expected := ttypes.Decimal{Bytes: decimal.BigIntToByte(big.NewInt(10200000000), 22, 9), Precision: 22, Scale: 9}
expected := types.Decimal{Bytes: decimal.BigIntToByte(big.NewInt(10200000000), 22), Precision: 22, Scale: 9}
err := scanner.ScanStruct(&row)
require.NoError(t, err)
require.Equal(t, expected, row.A)
Expand Down Expand Up @@ -964,9 +964,9 @@ func TestScannerDecimalNegative(t *testing.T) {
},
))
var row struct {
A ttypes.Decimal
A types.Decimal
}
expected := ttypes.Decimal{Bytes: decimal.BigIntToByte(big.NewInt(-2005000000), 22, 9), Precision: 22, Scale: 9}
expected := types.Decimal{Bytes: decimal.BigIntToByte(big.NewInt(-2005000000), 22), Precision: 22, Scale: 9}
err := scanner.ScanStruct(&row)
require.NoError(t, err)
require.Equal(t, expected, row.A)
Expand Down Expand Up @@ -995,7 +995,7 @@ func TestScannerDecimalBigDecimal(t *testing.T) {
},
))
var row struct {
A ttypes.Decimal
A types.Decimal
}
expectedVal := decimal.Decimal{
Bytes: [16]byte{0, 19, 66, 97, 114, 199, 77, 130, 43, 135, 143, 232, 0, 0, 0, 0},
Expand Down
2 changes: 1 addition & 1 deletion internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/google/uuid"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/decimal"
)

// RawValue scanning non-primitive yql types or for own implementation scanner native API
Expand Down
2 changes: 1 addition & 1 deletion internal/table/scanner/scan_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"github.com/google/uuid"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/xstring"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/table/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/google/uuid"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/scanner"
internalTypes "github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsync"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/xstring"
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
"github.com/ydb-platform/ydb-go-sdk/v3/table/result"
Expand Down
3 changes: 3 additions & 0 deletions internal/value/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package value

import (
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/xstring"
)

Expand Down Expand Up @@ -88,6 +89,8 @@ func Any(v Value) (any, error) { //nolint:funlen,gocyclo
return xstring.ToBytes(string(vv)), nil
case jsonDocumentValue:
return xstring.ToBytes(string(vv)), nil
case *decimalValue:
return decimal.ToDecimal(vv), nil
default:
return v, nil
}
Expand Down
29 changes: 7 additions & 22 deletions internal/value/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"github.com/google/uuid"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/decimal"
"github.com/ydb-platform/ydb-go-sdk/v3/pkg/xstring"
)

Expand Down Expand Up @@ -581,29 +581,15 @@ func Datetime64ValueFromTime(t time.Time) datetime64Value {
return datetime64Value(t.Unix())
}

var _ DecimalValuer = (*decimalValue)(nil)
var _ decimal.Interface = (*decimalValue)(nil)

type decimalValue struct {
value [16]byte
innerType *types.Decimal
}

func (v *decimalValue) Value() [16]byte {
return v.value
}

func (v *decimalValue) Precision() uint32 {
return v.innerType.Precision()
}

func (v *decimalValue) Scale() uint32 {
return v.innerType.Scale()
}

type DecimalValuer interface {
Value() [16]byte
Precision() uint32
Scale() uint32
func (v *decimalValue) Decimal() (bytes [16]byte, precision uint32, scale uint32) {
return v.value, v.innerType.Precision(), v.innerType.Scale()
}

func (v *decimalValue) castTo(dst any) error {
Expand All @@ -613,8 +599,7 @@ func (v *decimalValue) castTo(dst any) error {

return nil
case *decimal.Decimal:
decVal := decimal.Decimal{Bytes: v.value, Precision: v.Precision(), Scale: v.Scale()}
*dstValue = decVal
*dstValue = *decimal.ToDecimal(v)

return nil
default:
Expand All @@ -631,7 +616,7 @@ func (v *decimalValue) Yql() string {
buffer.WriteString(v.innerType.Name())
buffer.WriteByte('(')
buffer.WriteByte('"')
s := decimal.FromBytes(v.value[:], v.innerType.Precision(), v.innerType.Scale()).String()
s := decimal.FromBytes(v.value[:], v.innerType.Precision()).String()
if len(s) < int(v.innerType.Scale()) {
s = strings.Repeat("0", int(v.innerType.Scale())-len(s)) + s
}
Expand Down Expand Up @@ -665,7 +650,7 @@ func (v *decimalValue) toYDB() *Ydb.Value {
}

func DecimalValueFromBigInt(v *big.Int, precision, scale uint32) *decimalValue {
b := decimal.BigIntToByte(v, precision, scale)
b := decimal.BigIntToByte(v, precision)

return DecimalValue(b, precision, scale)
}
Expand Down
7 changes: 4 additions & 3 deletions internal/value/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1926,9 +1926,10 @@ func TestDecimalValue(t *testing.T) {
decBytes := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
v := DecimalValue(decBytes, 22, 9)
require.NotNil(t, v)
require.Equal(t, decBytes, v.Value())
require.Equal(t, uint32(22), v.Precision())
require.Equal(t, uint32(9), v.Scale())
bytes, precision, scale := v.Decimal()
require.Equal(t, decBytes, bytes)
require.Equal(t, uint32(22), precision)
require.Equal(t, uint32(9), scale)
})

t.Run("FromString", func(t *testing.T) {
Expand Down
File renamed without changes.
Loading
Loading