Skip to content

Commit df32151

Browse files
authored
Merge pull request #1289 from ydb-platform/revert-int-to-uint
* Reverted the allowing the casts from signed YDB types to unsigned d…
2 parents 453b8a6 + 845510b commit df32151

File tree

3 files changed

+1
-265
lines changed

3 files changed

+1
-265
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* Removed check the node is available for query and table service sessions
22
* Refactored the `balancers.PreferLocations()` function - it is a clean/pure function
33
* Added experimental `balancers.WithNodeID()` context modifier for define per request the YDB endpoint by NodeID
4+
* Reverted the allowing the casts from signed YDB types to unsigned destination types if source value is not negative
45

56
## v3.74.2
67
* Added description to scan errors with use query service client scanner

internal/value/value.go

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ func FloatValue(v float32) *floatValue {
788788

789789
type int8Value int8
790790

791-
//nolint:funlen
792791
func (v int8Value) castTo(dst interface{}) error {
793792
switch vv := dst.(type) {
794793
case *string:
@@ -804,65 +803,21 @@ func (v int8Value) castTo(dst interface{}) error {
804803

805804
return nil
806805

807-
case *uint64:
808-
if v < 0 {
809-
return xerrors.WithStackTrace(fmt.Errorf(
810-
"%w '%s(%+v)' to '%T' destination",
811-
ErrCannotCast, v.Type().Yql(), v, vv,
812-
))
813-
}
814-
815-
*vv = uint64(v)
816-
817-
return nil
818806
case *int32:
819807
*vv = int32(v)
820808

821809
return nil
822810

823-
case *uint32:
824-
if v < 0 {
825-
return xerrors.WithStackTrace(fmt.Errorf(
826-
"%w '%s(%+v)' to '%T' destination",
827-
ErrCannotCast, v.Type().Yql(), v, vv,
828-
))
829-
}
830-
831-
*vv = uint32(v)
832-
833-
return nil
834811
case *int16:
835812
*vv = int16(v)
836813

837814
return nil
838815

839-
case *uint16:
840-
if v < 0 {
841-
return xerrors.WithStackTrace(fmt.Errorf(
842-
"%w '%s(%+v)' to '%T' destination",
843-
ErrCannotCast, v.Type().Yql(), v, vv,
844-
))
845-
}
846-
847-
*vv = uint16(v)
848-
849-
return nil
850816
case *int8:
851817
*vv = int8(v)
852818

853819
return nil
854820

855-
case *uint8:
856-
if v < 0 {
857-
return xerrors.WithStackTrace(fmt.Errorf(
858-
"%w '%s(%+v)' to '%T' destination",
859-
ErrCannotCast, v.Type().Yql(), v, vv,
860-
))
861-
}
862-
863-
*vv = uint8(v)
864-
865-
return nil
866821
case *float64:
867822
*vv = float64(v)
868823

@@ -965,7 +920,6 @@ func Int16Value(v int16) int16Value {
965920

966921
type int32Value int32
967922

968-
//nolint:funlen
969923
func (v int32Value) castTo(dst interface{}) error {
970924
switch vv := dst.(type) {
971925
case *string:
@@ -981,49 +935,16 @@ func (v int32Value) castTo(dst interface{}) error {
981935

982936
return nil
983937

984-
case *uint64:
985-
if v < 0 {
986-
return xerrors.WithStackTrace(fmt.Errorf(
987-
"%w '%s(%+v)' to '%T' destination",
988-
ErrCannotCast, v.Type().Yql(), v, vv,
989-
))
990-
}
991-
992-
*vv = uint64(v)
993-
994-
return nil
995938
case *int:
996939
*vv = int(v)
997940

998941
return nil
999942

1000-
case *uint:
1001-
if v < 0 {
1002-
return xerrors.WithStackTrace(fmt.Errorf(
1003-
"%w '%s(%+v)' to '%T' destination",
1004-
ErrCannotCast, v.Type().Yql(), v, vv,
1005-
))
1006-
}
1007-
1008-
*vv = uint(v)
1009-
1010-
return nil
1011943
case *int32:
1012944
*vv = int32(v)
1013945

1014946
return nil
1015947

1016-
case *uint32:
1017-
if v < 0 {
1018-
return xerrors.WithStackTrace(fmt.Errorf(
1019-
"%w '%s(%+v)' to '%T' destination",
1020-
ErrCannotCast, v.Type().Yql(), v, vv,
1021-
))
1022-
}
1023-
1024-
*vv = uint32(v)
1025-
1026-
return nil
1027948
case *float64:
1028949
*vv = float64(v)
1029950

@@ -1079,17 +1000,6 @@ func (v int64Value) castTo(dst interface{}) error {
10791000

10801001
return nil
10811002

1082-
case *uint64:
1083-
if v < 0 {
1084-
return xerrors.WithStackTrace(fmt.Errorf(
1085-
"%w '%s(%+v)' to '%T' destination",
1086-
ErrCannotCast, v.Type().Yql(), v, vv,
1087-
))
1088-
}
1089-
1090-
*vv = uint64(v)
1091-
1092-
return nil
10931003
case *float64:
10941004
*vv = float64(v)
10951005

internal/value/value_test.go

Lines changed: 0 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,181 +1082,6 @@ func TestCastNumbers(t *testing.T) {
10821082
}
10831083
}
10841084

1085-
func TestCastNegativeNumbers(t *testing.T) {
1086-
for _, tt := range []struct {
1087-
value Value
1088-
dst interface{}
1089-
err error
1090-
}{
1091-
{
1092-
value: Int64Value(1),
1093-
dst: ptr[uint64](),
1094-
},
1095-
{
1096-
value: Int64Value(-2),
1097-
dst: ptr[uint64](),
1098-
err: ErrCannotCast,
1099-
},
1100-
{
1101-
value: Int64Value(1),
1102-
dst: ptr[uint32](),
1103-
err: ErrCannotCast,
1104-
},
1105-
{
1106-
value: Int64Value(-2),
1107-
dst: ptr[uint32](),
1108-
err: ErrCannotCast,
1109-
},
1110-
{
1111-
value: Int64Value(1),
1112-
dst: ptr[uint16](),
1113-
err: ErrCannotCast,
1114-
},
1115-
{
1116-
value: Int64Value(-2),
1117-
dst: ptr[uint16](),
1118-
err: ErrCannotCast,
1119-
},
1120-
{
1121-
value: Int64Value(1),
1122-
dst: ptr[uint8](),
1123-
err: ErrCannotCast,
1124-
},
1125-
{
1126-
value: Int64Value(-2),
1127-
dst: ptr[uint8](),
1128-
err: ErrCannotCast,
1129-
},
1130-
{
1131-
value: Int32Value(1),
1132-
dst: ptr[uint64](),
1133-
},
1134-
{
1135-
value: Int32Value(-2),
1136-
dst: ptr[uint64](),
1137-
err: ErrCannotCast,
1138-
},
1139-
{
1140-
value: Int32Value(1),
1141-
dst: ptr[uint32](),
1142-
},
1143-
{
1144-
value: Int32Value(-2),
1145-
dst: ptr[uint32](),
1146-
err: ErrCannotCast,
1147-
},
1148-
{
1149-
value: Int32Value(1),
1150-
dst: ptr[uint16](),
1151-
err: ErrCannotCast,
1152-
},
1153-
{
1154-
value: Int32Value(-2),
1155-
dst: ptr[uint16](),
1156-
err: ErrCannotCast,
1157-
},
1158-
{
1159-
value: Int32Value(1),
1160-
dst: ptr[uint8](),
1161-
err: ErrCannotCast,
1162-
},
1163-
{
1164-
value: Int32Value(-2),
1165-
dst: ptr[uint8](),
1166-
err: ErrCannotCast,
1167-
},
1168-
1169-
{
1170-
value: Int16Value(1),
1171-
dst: ptr[uint64](),
1172-
err: ErrCannotCast,
1173-
},
1174-
{
1175-
value: Int16Value(-2),
1176-
dst: ptr[uint64](),
1177-
err: ErrCannotCast,
1178-
},
1179-
{
1180-
value: Int16Value(1),
1181-
dst: ptr[uint32](),
1182-
err: ErrCannotCast,
1183-
},
1184-
{
1185-
value: Int16Value(-2),
1186-
dst: ptr[uint32](),
1187-
err: ErrCannotCast,
1188-
},
1189-
{
1190-
value: Int16Value(1),
1191-
dst: ptr[uint16](),
1192-
err: ErrCannotCast,
1193-
},
1194-
{
1195-
value: Int16Value(-2),
1196-
dst: ptr[uint16](),
1197-
err: ErrCannotCast,
1198-
},
1199-
{
1200-
value: Int16Value(1),
1201-
dst: ptr[uint8](),
1202-
err: ErrCannotCast,
1203-
},
1204-
{
1205-
value: Int32Value(-2),
1206-
dst: ptr[uint8](),
1207-
err: ErrCannotCast,
1208-
},
1209-
1210-
{
1211-
value: Int8Value(1),
1212-
dst: ptr[uint64](),
1213-
},
1214-
{
1215-
value: Int8Value(-2),
1216-
dst: ptr[uint64](),
1217-
err: ErrCannotCast,
1218-
},
1219-
{
1220-
value: Int8Value(1),
1221-
dst: ptr[uint32](),
1222-
},
1223-
{
1224-
value: Int8Value(-2),
1225-
dst: ptr[uint32](),
1226-
err: ErrCannotCast,
1227-
},
1228-
{
1229-
value: Int8Value(1),
1230-
dst: ptr[uint16](),
1231-
},
1232-
{
1233-
value: Int8Value(-2),
1234-
dst: ptr[uint16](),
1235-
err: ErrCannotCast,
1236-
},
1237-
{
1238-
value: Int8Value(1),
1239-
dst: ptr[uint8](),
1240-
},
1241-
{
1242-
value: Int8Value(-2),
1243-
dst: ptr[uint8](),
1244-
err: ErrCannotCast,
1245-
},
1246-
} {
1247-
t.Run(fmt.Sprintf("%s(%s)→%s",
1248-
tt.value.Type().Yql(), tt.value.Yql(), reflect.ValueOf(tt.dst).Type().Elem().String(),
1249-
), func(t *testing.T) {
1250-
err := CastTo(tt.value, tt.dst)
1251-
if tt.err != nil {
1252-
require.ErrorIs(t, err, tt.err)
1253-
} else {
1254-
require.NoError(t, err)
1255-
}
1256-
})
1257-
}
1258-
}
1259-
12601085
func TestCastOtherTypes(t *testing.T) {
12611086
for _, tt := range []struct {
12621087
v Value

0 commit comments

Comments
 (0)