Skip to content
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

uuid-fix #1513

Merged
merged 30 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a96fc1f
add regression test
rekby Oct 7, 2024
e7f058a
commit old behavior for test
rekby Oct 8, 2024
617609a
good read from uuid from server
rekby Oct 8, 2024
5606882
work scan to old formats
rekby Oct 10, 2024
3d0e44a
add declare
rekby Oct 10, 2024
39a8cbe
Merge branch 'master' into uuid-fix
rekby Oct 14, 2024
49324dc
add table test for typed uuid reader
rekby Oct 14, 2024
4be32a3
add uuid fixes
rekby Oct 16, 2024
918afe7
test scanner interface
rekby Oct 16, 2024
101dca3
add deprecated comments
rekby Oct 17, 2024
2c93941
add some database sql tests
rekby Oct 17, 2024
c5e9db9
Merge branch 'uuid-current-behavior' into uuid-fix
rekby Oct 17, 2024
dd96a11
fix some tests
rekby Oct 17, 2024
ceae511
add migration way for database sql users
rekby Oct 17, 2024
1f18d4c
add database sql tests
rekby Oct 17, 2024
08fb571
fix declare
rekby Oct 17, 2024
aa433f9
fix for linter
rekby Oct 17, 2024
f75dce7
remove some additional types, refactor wrapper to struct for prevent …
rekby Oct 17, 2024
5a28a27
deprecation comment for raw
rekby Oct 17, 2024
6ea905e
add changelog
rekby Oct 17, 2024
d27e39c
Merge branch 'master' into uuid-fix
rekby Oct 17, 2024
2199911
fix scan bytes
rekby Oct 17, 2024
b648513
fix param tests
rekby Oct 17, 2024
d1fcd9a
fix param tests
rekby Oct 17, 2024
d81eeb4
fix param tests
rekby Oct 17, 2024
a7f32cf
Merge branch 'master' into uuid-fix
rekby Oct 22, 2024
0144f86
renamed UUIDTyped to Uuid and add Uuid to values
rekby Oct 22, 2024
53817cb
Merge branch 'master' into uuid-fix
rekby Oct 22, 2024
8eded67
Merge branch 'master' into uuid-fix
rekby Oct 23, 2024
51e3a6c
fix transaction control
rekby Oct 23, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Add workaround for bug in uuid send/receive from server. It is migration version. All native code and most database sql code worked with uuid continue to work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

## v3.85.3
* Renamed `query.WithPoolID()` into `query.WithResourcePool()`

Expand Down
17 changes: 16 additions & 1 deletion internal/bind/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"sort"
"time"

"github.com/google/uuid"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/params"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
Expand Down Expand Up @@ -113,9 +115,22 @@ func toValue(v interface{}) (_ types.Value, err error) {

return types.ListValue(items...), nil
case [16]byte:
return types.UUIDValue(x), nil
return types.UUIDValue(x), nil //nolint:staticcheck
case *[16]byte:
return types.NullableUUIDValue(x), nil
case types.UUIDBytesWithIssue1501Type:
return types.UUIDWithIssue1501Value(x.AsBytesArray()), nil
case *types.UUIDBytesWithIssue1501Type:
if x == nil {
return types.NullableUUIDValueWithIssue1501(nil), nil
}
val := x.AsBytesArray()

return types.NullableUUIDValueWithIssue1501(&val), nil
case uuid.UUID:
return types.UuidValue(x), nil
case *uuid.UUID:
return types.NullableUUIDTypedValue(x), nil
case time.Time:
return types.TimestampValueFromTime(x), nil
case *time.Time:
Expand Down
28 changes: 23 additions & 5 deletions internal/bind/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/require"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/params"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)
Expand Down Expand Up @@ -280,20 +282,36 @@ func TestToValue(t *testing.T) {

{
src: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
dst: types.UUIDValue([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}),
dst: types.UUIDValue([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}), //nolint:staticcheck
err: nil,
},
{
src: func() *[16]byte { return nil }(),
dst: types.NullValue(types.TypeUUID),
err: nil,
},
{
src: func(v [16]byte) *[16]byte { return &v }([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}),
dst: types.OptionalValue(types.UUIDValue([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})),
dst: types.OptionalValue(types.UUIDValue([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})), //nolint:staticcheck,lll
err: nil,
},
{
src: func() *[16]byte { return nil }(),
dst: types.NullValue(types.TypeUUID),
src: uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
dst: value.TextValue("01020304-0506-0708-090a-0b0c0d0e0f10"),
err: nil,
},

{
src: func(v uuid.UUID) *uuid.UUID { return &v }(uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}),
// uuid implemented driver.Valuer and doesn't set optional wrapper
dst: types.TextValue("01020304-0506-0708-090a-0b0c0d0e0f10"),
err: nil,
},
// https://github.com/ydb-platform/ydb-go-sdk/issues/1515
//{
// src: func() *uuid.UUID { return nil }(),
// dst: nil,
// err: nil,
//},
{
src: time.Unix(42, 43),
dst: types.TimestampValueFromTime(time.Unix(42, 43)),
Expand Down
48 changes: 46 additions & 2 deletions internal/params/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package params
import (
"time"

"github.com/google/uuid"

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

Expand Down Expand Up @@ -201,8 +203,28 @@ func (d *dictPair) YSON(v []byte) *dictValue {
}
}

// UUID has data corruption bug and will be removed in next version.
//
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
func (d *dictPair) UUID(v [16]byte) *dictValue {
d.keyValue = value.UUIDValue(v)
d.keyValue = value.UUIDWithIssue1501Value(v)

return &dictValue{
pair: d,
}
}

func (d *dictPair) Uuid(v uuid.UUID) *dictValue { //nolint:revive,stylecheck
d.keyValue = value.Uuid(v)

return &dictValue{
pair: d,
}
}

func (d *dictPair) UUIDWithIssue1501Value(v [16]byte) *dictValue {
d.keyValue = value.UUIDWithIssue1501Value(v)

return &dictValue{
pair: d,
Expand Down Expand Up @@ -422,10 +444,32 @@ func (d *dictValue) YSON(v []byte) *dict {
return d.pair.parent
}

// UUID has data corruption bug and will be removed in next version.
//
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
func (d *dictValue) UUID(v [16]byte) *dict {
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
K: d.pair.keyValue,
V: value.UUIDValue(v),
V: value.UUIDWithIssue1501Value(v),
})

return d.pair.parent
}

func (d *dictValue) Uuid(v uuid.UUID) *dict { //nolint:revive,stylecheck
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
K: d.pair.keyValue,
V: value.Uuid(v),
})

return d.pair.parent
}

func (d *dictValue) UUIDWithIssue1501Value(v [16]byte) *dict {
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
K: d.pair.keyValue,
V: value.UUIDWithIssue1501Value(v),
})

return d.pair.parent
Expand Down
33 changes: 33 additions & 0 deletions internal/params/dict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

Expand Down Expand Up @@ -362,6 +363,38 @@ func TestDict(t *testing.T) {
},
},
},
{
method: "Uuid",
args: []any{uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},

expected: expected{
Type: &Ydb.Type{
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
},
Value: &Ydb.Value{
Value: &Ydb.Value_Low_128{
Low_128: 506660481424032516,
},
High_128: 1157159078456920585,
},
},
},
{
method: "UUIDWithIssue1501Value",
args: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},

expected: expected{
Type: &Ydb.Type{
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
},
Value: &Ydb.Value{
Value: &Ydb.Value_Low_128{
Low_128: 651345242494996240,
},
High_128: 72623859790382856,
},
},
},
{
method: "TzDatetime",
args: []any{time.Unix(123456789, 456).UTC()},
Expand Down
20 changes: 19 additions & 1 deletion internal/params/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package params
import (
"time"

"github.com/google/uuid"

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

Expand Down Expand Up @@ -165,8 +167,24 @@ func (l *listItem) YSON(v []byte) *list {
return l.parent
}

// UUID has data corruption bug and will be removed in next version.
//
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
func (l *listItem) UUID(v [16]byte) *list {
l.parent.values = append(l.parent.values, value.UUIDValue(v))
l.parent.values = append(l.parent.values, value.UUIDWithIssue1501Value(v))

return l.parent
}

func (l *listItem) Uuid(v uuid.UUID) *list { //nolint:revive,stylecheck
l.parent.values = append(l.parent.values, value.Uuid(v))

return l.parent
}

func (l *listItem) UUIDWithIssue1501Value(v [16]byte) *list {
l.parent.values = append(l.parent.values, value.UUIDWithIssue1501Value(v))

return l.parent
}
Expand Down
33 changes: 33 additions & 0 deletions internal/params/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

Expand Down Expand Up @@ -361,6 +362,38 @@ func TestList(t *testing.T) {
},
},
},
{
method: "Uuid",
args: []any{uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},

expected: expected{
Type: &Ydb.Type{
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
},
Value: &Ydb.Value{
Value: &Ydb.Value_Low_128{
Low_128: 506660481424032516,
},
High_128: 1157159078456920585,
},
},
},
{
method: "UUIDWithIssue1501Value",
args: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},

expected: expected{
Type: &Ydb.Type{
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
},
Value: &Ydb.Value{
Value: &Ydb.Value_Low_128{
Low_128: 651345242494996240,
},
High_128: 72623859790382856,
},
},
},
{
method: "TzDatetime",
args: []any{time.Unix(123456789, 456).UTC()},
Expand Down
18 changes: 18 additions & 0 deletions internal/params/optional.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package params
import (
"time"

"github.com/google/uuid"

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

Expand Down Expand Up @@ -153,12 +155,28 @@ func (p *optional) YSON(v *[]byte) *optionalBuilder {
return &optionalBuilder{opt: p}
}

// UUID has data corruption bug and will be removed in next version.
//
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
func (p *optional) UUID(v *[16]byte) *optionalBuilder {
p.value = value.NullableUUIDValue(v)

return &optionalBuilder{opt: p}
}

func (p *optional) Uuid(v *uuid.UUID) *optionalBuilder { //nolint:revive,stylecheck
p.value = value.NullableUuidValue(v)

return &optionalBuilder{opt: p}
}

func (p *optional) UUIDWithIssue1501Value(v *[16]byte) *optionalBuilder {
p.value = value.NullableUUIDValue(v)

return &optionalBuilder{opt: p}
}

func (p *optional) TzDate(v *time.Time) *optionalBuilder {
p.value = value.NullableTzDateValueFromTime(v)

Expand Down
53 changes: 53 additions & 0 deletions internal/params/optional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

Expand Down Expand Up @@ -580,6 +581,58 @@ func TestOptional(t *testing.T) {
},
},
},
{
method: "Uuid",
args: []any{p(uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})},

expected: expected{
Type: &Ydb.Type{
Type: &Ydb.Type_OptionalType{
OptionalType: &Ydb.OptionalType{
Item: &Ydb.Type{
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
},
},
},
},
Value: &Ydb.Value{
Value: &Ydb.Value_NestedValue{
NestedValue: &Ydb.Value{
Value: &Ydb.Value_Low_128{
Low_128: 506660481424032516,
},
High_128: 1157159078456920585,
},
},
},
},
},
{
method: "UUIDWithIssue1501Value",
args: []any{p([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})},

expected: expected{
Type: &Ydb.Type{
Type: &Ydb.Type_OptionalType{
OptionalType: &Ydb.OptionalType{
Item: &Ydb.Type{
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
},
},
},
},
Value: &Ydb.Value{
Value: &Ydb.Value_NestedValue{
NestedValue: &Ydb.Value{
Value: &Ydb.Value_Low_128{
Low_128: 651345242494996240,
},
High_128: 72623859790382856,
},
},
},
},
},
{
method: "TzDatetime",
args: []any{p(time.Unix(123456789, 456).UTC())},
Expand Down
Loading
Loading