Skip to content

Commit 5b9945c

Browse files
authored
Merge pull request #1523 UUID break old code
2 parents a89f8a4 + a33a5f2 commit 5b9945c

File tree

17 files changed

+68
-297
lines changed

17 files changed

+68
-297
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
* BREAK OLD STYLE WORK WITH UUID. See https://github.com/ydb-platform/ydb-go-sdk/issues/1501 for details.
2+
At the version you must explicit choose way for work with uuid: old with bug or new (fixed).
3+
14
## v3.86.1
25
* Fixed scan to optional uuid
36

47
## v3.86.0
58
* 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.
9+
Dedicated version for migrate code for workaround/fix uuid bug. See https://github.com/ydb-platform/ydb-go-sdk/issues/1501 for details.
610

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

internal/bind/params.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ func toValue(v interface{}) (_ types.Value, err error) {
115115

116116
return types.ListValue(items...), nil
117117
case [16]byte:
118-
return types.UUIDValue(x), nil //nolint:staticcheck
118+
return nil, xerrors.Wrap(value.ErrIssue1501BadUUID)
119119
case *[16]byte:
120-
return types.NullableUUIDValue(x), nil
120+
return nil, xerrors.Wrap(value.ErrIssue1501BadUUID)
121121
case types.UUIDBytesWithIssue1501Type:
122122
return types.UUIDWithIssue1501Value(x.AsBytesArray()), nil
123123
case *types.UUIDBytesWithIssue1501Type:

internal/bind/params_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,21 +279,20 @@ func TestToValue(t *testing.T) {
279279
dst: types.ListValue(types.TextValue("test")),
280280
err: nil,
281281
},
282-
283282
{
284283
src: [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,
284+
dst: nil,
285+
err: types.ErrIssue1501BadUUID,
287286
},
288287
{
289288
src: func() *[16]byte { return nil }(),
290-
dst: types.NullValue(types.TypeUUID),
291-
err: nil,
289+
dst: nil,
290+
err: types.ErrIssue1501BadUUID,
292291
},
293292
{
294293
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}),
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
296-
err: nil,
294+
dst: nil,
295+
err: types.ErrIssue1501BadUUID,
297296
},
298297
{
299298
src: uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},

internal/params/builder_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,22 +345,6 @@ func TestBuilder(t *testing.T) {
345345
},
346346
},
347347
},
348-
{
349-
method: "UUID",
350-
args: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
351-
352-
expected: expected{
353-
Type: &Ydb.Type{
354-
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
355-
},
356-
Value: &Ydb.Value{
357-
Value: &Ydb.Value_Low_128{
358-
Low_128: 651345242494996240,
359-
},
360-
High_128: 72623859790382856,
361-
},
362-
},
363-
},
364348
{
365349
method: "TzDatetime",
366350
args: []any{time.Unix(123456789, 456).UTC()},

internal/params/parameters.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,10 @@ func (p *Parameter) YSON(v []byte) Builder {
297297
return p.parent
298298
}
299299

300-
// UUID has data corruption bug and will be removed in next version.
301-
//
302-
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
303-
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
304-
func (p *Parameter) UUID(v [16]byte) Builder {
305-
return p.UUIDWithIssue1501Value(v)
306-
}
300+
// removed for https://github.com/ydb-platform/ydb-go-sdk/issues/1501
301+
//func (p *Parameter) UUID(v [16]byte) Builder {
302+
// return p.UUIDWithIssue1501Value(v)
303+
//}
307304

308305
// UUIDWithIssue1501Value is field serializer for save data with format bug.
309306
// For any new code use Uuid

internal/scanner/scanner.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ type RawValue interface {
3838
UTF8() (v string)
3939
YSON() (v []byte)
4040
JSON() (v []byte)
41-
42-
// UUID has data corruption bug and will be removed in next version.
43-
//
44-
// Deprecated: Use UUIDTyped (prefer) or UUIDWithIssue1501 (for save old behavior) instead.
45-
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
46-
UUID() (v [16]byte)
41+
// UUID() (v [16]byte) removed for https://github.com/ydb-platform/ydb-go-sdk/issues/1501
4742
UUIDTyped() (v uuid.UUID)
4843
UUIDWithIssue1501() (v [16]byte)
4944
JSONDocument() (v []byte)

internal/table/scanner/scan_raw.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,10 @@ func (s *rawConverter) JSONDocument() (v []byte) {
263263
return xstring.ToBytes(s.text())
264264
}
265265

266-
func (s *rawConverter) UUID() (v [16]byte) {
267-
return s.uuidBytesWithIssue1501().AsBytesArray()
268-
}
266+
// removed for https://github.com/ydb-platform/ydb-go-sdk/issues/1501
267+
//func (s *rawConverter) UUID() (v [16]byte) {
268+
// return s.uuidBytesWithIssue1501().AsBytesArray()
269+
//}
269270

270271
func (s *rawConverter) UUIDWithIssue1501() (v [16]byte) {
271272
if s.Err() != nil {

internal/table/scanner/scanner.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ func (s *valueScanner) low128() (v uint64) {
694694

695695
func (s *valueScanner) uint128() (v [16]byte) {
696696
if s.stack.current().t.GetTypeId() == Ydb.Type_UUID {
697-
return s.uuidBytesWithIssue1501().AsBytesArray()
697+
_ = s.errorf(0, "ydb: failed to scan uuid: %w", value.ErrIssue1501BadUUID)
698698
}
699699

700700
c := s.stack.current()
@@ -786,7 +786,7 @@ func (s *valueScanner) setTime(dst *time.Time) {
786786
func (s *valueScanner) setString(dst *string) {
787787
switch t := s.stack.current().t.GetTypeId(); t {
788788
case Ydb.Type_UUID:
789-
s.setUUIDStringWith1501Issue(dst)
789+
_ = s.errorf(0, "ydb: failed scan uuid: %w", value.ErrIssue1501BadUUID)
790790
case Ydb.Type_UTF8, Ydb.Type_DYNUMBER, Ydb.Type_YSON, Ydb.Type_JSON, Ydb.Type_JSON_DOCUMENT:
791791
*dst = s.text()
792792
case Ydb.Type_STRING:
@@ -796,19 +796,10 @@ func (s *valueScanner) setString(dst *string) {
796796
}
797797
}
798798

799-
func (s *valueScanner) setUUIDStringWith1501Issue(dst *string) {
800-
switch t := s.stack.current().t.GetTypeId(); t {
801-
case Ydb.Type_UUID:
802-
*dst = s.uuidBytesWithIssue1501().AsBrokenString()
803-
default:
804-
_ = s.errorf(0, "scan row failed: incorrect source types %s", t)
805-
}
806-
}
807-
808799
func (s *valueScanner) setByte(dst *[]byte) {
809800
switch t := s.stack.current().t.GetTypeId(); t {
810801
case Ydb.Type_UUID:
811-
s.setUUIDWithIssue1501Byte(dst)
802+
_ = s.errorf(0, "ydb: failed to scan uuid: %w", value.ErrIssue1501BadUUID)
812803
case Ydb.Type_UTF8, Ydb.Type_DYNUMBER, Ydb.Type_YSON, Ydb.Type_JSON, Ydb.Type_JSON_DOCUMENT:
813804
*dst = xstring.ToBytes(s.text())
814805
case Ydb.Type_STRING:
@@ -818,15 +809,6 @@ func (s *valueScanner) setByte(dst *[]byte) {
818809
}
819810
}
820811

821-
func (s *valueScanner) setUUIDWithIssue1501Byte(dst *[]byte) {
822-
switch t := s.stack.current().t.GetTypeId(); t {
823-
case Ydb.Type_UUID:
824-
*dst = s.uuidBytesWithIssue1501().AsBytesSlice()
825-
default:
826-
_ = s.errorf(0, "scan row failed: incorrect source type %s", t)
827-
}
828-
}
829-
830812
func (s *valueScanner) trySetByteArray(v interface{}, optional, def bool) bool {
831813
rv := reflect.ValueOf(v)
832814
if rv.Kind() == reflect.Ptr {

internal/table/scanner/scanner_data_test.go

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

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

1011
"github.com/ydb-platform/ydb-go-sdk/v3/table/result/indexed"
@@ -63,7 +64,7 @@ var scannerData = []struct {
6364
name: "date",
6465
typeID: Ydb.Type_DATE,
6566
}},
66-
values: []indexed.RequiredOrOptional{new([16]byte), new(time.Time)},
67+
values: []indexed.RequiredOrOptional{new(uuid.UUID), new(time.Time)},
6768
},
6869
{
6970
name: "Scan JSON, DOUBLE",
@@ -272,7 +273,7 @@ var scannerData = []struct {
272273
typeID: Ydb.Type_DOUBLE,
273274
optional: true,
274275
}},
275-
values: []indexed.RequiredOrOptional{new(*time.Duration), new(*[16]byte), new(*float64)},
276+
values: []indexed.RequiredOrOptional{new(*time.Duration), new(*uuid.UUID), new(*float64)},
276277
},
277278
{
278279
name: "Scan int64, date, string as ydb.Scanner",
@@ -424,7 +425,7 @@ var scannerData = []struct {
424425
optional: true,
425426
nilValue: true,
426427
}},
427-
values: []indexed.RequiredOrOptional{new(*uint8), new(*[]byte), new(*time.Time), new(*[16]byte)},
428+
values: []indexed.RequiredOrOptional{new(*uint8), new(*[]byte), new(*time.Time), new(*uuid.UUID)},
428429
},
429430
{
430431
name: "Scan string as byte array.",

internal/table/scanner/scanner_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"time"
1010

11+
"github.com/google/uuid"
1112
"github.com/stretchr/testify/require"
1213
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
1314

@@ -454,21 +455,23 @@ func valueFromPrimitiveTypeID(c *column, r xrand.Rand) (*Ydb.Value, interface{})
454455
Value: &Ydb.Value_NullFlagValue{},
455456
}
456457
if c.testDefault {
457-
var dv [16]byte
458+
var dv uuid.UUID
458459

459460
return ydbval, &dv
460461
}
461-
var dv *[16]byte
462+
var dv *uuid.UUID
462463

463464
return ydbval, &dv
464465
}
465-
v := [16]byte{}
466-
binary.BigEndian.PutUint64(v[0:8], uint64(rv))
467-
binary.BigEndian.PutUint64(v[8:16], uint64(rv))
466+
v := uuid.UUID{}
467+
468+
binary.LittleEndian.PutUint64(v[0:8], uint64(rv))
469+
binary.LittleEndian.PutUint64(v[8:16], uint64(rv))
470+
low, high := value.UUIDToHiLoPair(v)
468471
ydbval := &Ydb.Value{
469-
High_128: binary.BigEndian.Uint64(v[0:8]),
472+
High_128: high,
470473
Value: &Ydb.Value_Low_128{
471-
Low_128: binary.BigEndian.Uint64(v[8:16]),
474+
Low_128: low,
472475
},
473476
}
474477
if c.optional && !c.testDefault {

0 commit comments

Comments
 (0)