Skip to content

Commit 8e47d2c

Browse files
authored
Merge pull request #1513 migration version for UUID
2 parents 534c571 + 51e3a6c commit 8e47d2c

31 files changed

+1681
-55
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* 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.
2+
13
## v3.85.3
24
* Renamed `query.WithPoolID()` into `query.WithResourcePool()`
35

internal/bind/params.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"sort"
1010
"time"
1111

12+
"github.com/google/uuid"
13+
1214
"github.com/ydb-platform/ydb-go-sdk/v3/internal/params"
1315
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
1416
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
@@ -113,9 +115,22 @@ func toValue(v interface{}) (_ types.Value, err error) {
113115

114116
return types.ListValue(items...), nil
115117
case [16]byte:
116-
return types.UUIDValue(x), nil
118+
return types.UUIDValue(x), nil //nolint:staticcheck
117119
case *[16]byte:
118120
return types.NullableUUIDValue(x), nil
121+
case types.UUIDBytesWithIssue1501Type:
122+
return types.UUIDWithIssue1501Value(x.AsBytesArray()), nil
123+
case *types.UUIDBytesWithIssue1501Type:
124+
if x == nil {
125+
return types.NullableUUIDValueWithIssue1501(nil), nil
126+
}
127+
val := x.AsBytesArray()
128+
129+
return types.NullableUUIDValueWithIssue1501(&val), nil
130+
case uuid.UUID:
131+
return types.UuidValue(x), nil
132+
case *uuid.UUID:
133+
return types.NullableUUIDTypedValue(x), nil
119134
case time.Time:
120135
return types.TimestampValueFromTime(x), nil
121136
case *time.Time:

internal/bind/params_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"testing"
88
"time"
99

10+
"github.com/google/uuid"
1011
"github.com/stretchr/testify/require"
1112

1213
"github.com/ydb-platform/ydb-go-sdk/v3/internal/params"
14+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
1315
"github.com/ydb-platform/ydb-go-sdk/v3/table"
1416
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
1517
)
@@ -280,20 +282,36 @@ func TestToValue(t *testing.T) {
280282

281283
{
282284
src: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
283-
dst: types.UUIDValue([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}),
285+
dst: types.UUIDValue([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}), //nolint:staticcheck
286+
err: nil,
287+
},
288+
{
289+
src: func() *[16]byte { return nil }(),
290+
dst: types.NullValue(types.TypeUUID),
284291
err: nil,
285292
},
286293
{
287294
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}),
288-
dst: types.OptionalValue(types.UUIDValue([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})),
295+
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
289296
err: nil,
290297
},
291298
{
292-
src: func() *[16]byte { return nil }(),
293-
dst: types.NullValue(types.TypeUUID),
299+
src: uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
300+
dst: value.TextValue("01020304-0506-0708-090a-0b0c0d0e0f10"),
294301
err: nil,
295302
},
296-
303+
{
304+
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}),
305+
// uuid implemented driver.Valuer and doesn't set optional wrapper
306+
dst: types.TextValue("01020304-0506-0708-090a-0b0c0d0e0f10"),
307+
err: nil,
308+
},
309+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1515
310+
//{
311+
// src: func() *uuid.UUID { return nil }(),
312+
// dst: nil,
313+
// err: nil,
314+
//},
297315
{
298316
src: time.Unix(42, 43),
299317
dst: types.TimestampValueFromTime(time.Unix(42, 43)),

internal/params/dict.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package params
33
import (
44
"time"
55

6+
"github.com/google/uuid"
7+
68
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
79
)
810

@@ -201,8 +203,28 @@ func (d *dictPair) YSON(v []byte) *dictValue {
201203
}
202204
}
203205

206+
// UUID has data corruption bug and will be removed in next version.
207+
//
208+
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
209+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
204210
func (d *dictPair) UUID(v [16]byte) *dictValue {
205-
d.keyValue = value.UUIDValue(v)
211+
d.keyValue = value.UUIDWithIssue1501Value(v)
212+
213+
return &dictValue{
214+
pair: d,
215+
}
216+
}
217+
218+
func (d *dictPair) Uuid(v uuid.UUID) *dictValue { //nolint:revive,stylecheck
219+
d.keyValue = value.Uuid(v)
220+
221+
return &dictValue{
222+
pair: d,
223+
}
224+
}
225+
226+
func (d *dictPair) UUIDWithIssue1501Value(v [16]byte) *dictValue {
227+
d.keyValue = value.UUIDWithIssue1501Value(v)
206228

207229
return &dictValue{
208230
pair: d,
@@ -422,10 +444,32 @@ func (d *dictValue) YSON(v []byte) *dict {
422444
return d.pair.parent
423445
}
424446

447+
// UUID has data corruption bug and will be removed in next version.
448+
//
449+
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
450+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
425451
func (d *dictValue) UUID(v [16]byte) *dict {
426452
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
427453
K: d.pair.keyValue,
428-
V: value.UUIDValue(v),
454+
V: value.UUIDWithIssue1501Value(v),
455+
})
456+
457+
return d.pair.parent
458+
}
459+
460+
func (d *dictValue) Uuid(v uuid.UUID) *dict { //nolint:revive,stylecheck
461+
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
462+
K: d.pair.keyValue,
463+
V: value.Uuid(v),
464+
})
465+
466+
return d.pair.parent
467+
}
468+
469+
func (d *dictValue) UUIDWithIssue1501Value(v [16]byte) *dict {
470+
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
471+
K: d.pair.keyValue,
472+
V: value.UUIDWithIssue1501Value(v),
429473
})
430474

431475
return d.pair.parent

internal/params/dict_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/google/uuid"
89
"github.com/stretchr/testify/require"
910
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
1011

@@ -362,6 +363,38 @@ func TestDict(t *testing.T) {
362363
},
363364
},
364365
},
366+
{
367+
method: "Uuid",
368+
args: []any{uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
369+
370+
expected: expected{
371+
Type: &Ydb.Type{
372+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
373+
},
374+
Value: &Ydb.Value{
375+
Value: &Ydb.Value_Low_128{
376+
Low_128: 506660481424032516,
377+
},
378+
High_128: 1157159078456920585,
379+
},
380+
},
381+
},
382+
{
383+
method: "UUIDWithIssue1501Value",
384+
args: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
385+
386+
expected: expected{
387+
Type: &Ydb.Type{
388+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
389+
},
390+
Value: &Ydb.Value{
391+
Value: &Ydb.Value_Low_128{
392+
Low_128: 651345242494996240,
393+
},
394+
High_128: 72623859790382856,
395+
},
396+
},
397+
},
365398
{
366399
method: "TzDatetime",
367400
args: []any{time.Unix(123456789, 456).UTC()},

internal/params/list.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package params
33
import (
44
"time"
55

6+
"github.com/google/uuid"
7+
68
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
79
)
810

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

170+
// UUID has data corruption bug and will be removed in next version.
171+
//
172+
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
173+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
168174
func (l *listItem) UUID(v [16]byte) *list {
169-
l.parent.values = append(l.parent.values, value.UUIDValue(v))
175+
l.parent.values = append(l.parent.values, value.UUIDWithIssue1501Value(v))
176+
177+
return l.parent
178+
}
179+
180+
func (l *listItem) Uuid(v uuid.UUID) *list { //nolint:revive,stylecheck
181+
l.parent.values = append(l.parent.values, value.Uuid(v))
182+
183+
return l.parent
184+
}
185+
186+
func (l *listItem) UUIDWithIssue1501Value(v [16]byte) *list {
187+
l.parent.values = append(l.parent.values, value.UUIDWithIssue1501Value(v))
170188

171189
return l.parent
172190
}

internal/params/list_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/google/uuid"
78
"github.com/stretchr/testify/require"
89
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
910

@@ -361,6 +362,38 @@ func TestList(t *testing.T) {
361362
},
362363
},
363364
},
365+
{
366+
method: "Uuid",
367+
args: []any{uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
368+
369+
expected: expected{
370+
Type: &Ydb.Type{
371+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
372+
},
373+
Value: &Ydb.Value{
374+
Value: &Ydb.Value_Low_128{
375+
Low_128: 506660481424032516,
376+
},
377+
High_128: 1157159078456920585,
378+
},
379+
},
380+
},
381+
{
382+
method: "UUIDWithIssue1501Value",
383+
args: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
384+
385+
expected: expected{
386+
Type: &Ydb.Type{
387+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
388+
},
389+
Value: &Ydb.Value{
390+
Value: &Ydb.Value_Low_128{
391+
Low_128: 651345242494996240,
392+
},
393+
High_128: 72623859790382856,
394+
},
395+
},
396+
},
364397
{
365398
method: "TzDatetime",
366399
args: []any{time.Unix(123456789, 456).UTC()},

internal/params/optional.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package params
33
import (
44
"time"
55

6+
"github.com/google/uuid"
7+
68
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
79
)
810

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

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

159165
return &optionalBuilder{opt: p}
160166
}
161167

168+
func (p *optional) Uuid(v *uuid.UUID) *optionalBuilder { //nolint:revive,stylecheck
169+
p.value = value.NullableUuidValue(v)
170+
171+
return &optionalBuilder{opt: p}
172+
}
173+
174+
func (p *optional) UUIDWithIssue1501Value(v *[16]byte) *optionalBuilder {
175+
p.value = value.NullableUUIDValue(v)
176+
177+
return &optionalBuilder{opt: p}
178+
}
179+
162180
func (p *optional) TzDate(v *time.Time) *optionalBuilder {
163181
p.value = value.NullableTzDateValueFromTime(v)
164182

internal/params/optional_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/google/uuid"
78
"github.com/stretchr/testify/require"
89
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
910

@@ -580,6 +581,58 @@ func TestOptional(t *testing.T) {
580581
},
581582
},
582583
},
584+
{
585+
method: "Uuid",
586+
args: []any{p(uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})},
587+
588+
expected: expected{
589+
Type: &Ydb.Type{
590+
Type: &Ydb.Type_OptionalType{
591+
OptionalType: &Ydb.OptionalType{
592+
Item: &Ydb.Type{
593+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
594+
},
595+
},
596+
},
597+
},
598+
Value: &Ydb.Value{
599+
Value: &Ydb.Value_NestedValue{
600+
NestedValue: &Ydb.Value{
601+
Value: &Ydb.Value_Low_128{
602+
Low_128: 506660481424032516,
603+
},
604+
High_128: 1157159078456920585,
605+
},
606+
},
607+
},
608+
},
609+
},
610+
{
611+
method: "UUIDWithIssue1501Value",
612+
args: []any{p([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})},
613+
614+
expected: expected{
615+
Type: &Ydb.Type{
616+
Type: &Ydb.Type_OptionalType{
617+
OptionalType: &Ydb.OptionalType{
618+
Item: &Ydb.Type{
619+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
620+
},
621+
},
622+
},
623+
},
624+
Value: &Ydb.Value{
625+
Value: &Ydb.Value_NestedValue{
626+
NestedValue: &Ydb.Value{
627+
Value: &Ydb.Value_Low_128{
628+
Low_128: 651345242494996240,
629+
},
630+
High_128: 72623859790382856,
631+
},
632+
},
633+
},
634+
},
635+
},
583636
{
584637
method: "TzDatetime",
585638
args: []any{p(time.Unix(123456789, 456).UTC())},

0 commit comments

Comments
 (0)