Skip to content

Commit 6deb796

Browse files
committed
* Reverted the allowing the casts from signed YDB types to unsigned destination types if source value is not negative
1 parent 453b8a6 commit 6deb796

File tree

3 files changed

+1
-263
lines changed

3 files changed

+1
-263
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 & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -804,65 +804,21 @@ func (v int8Value) castTo(dst interface{}) error {
804804

805805
return nil
806806

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
818807
case *int32:
819808
*vv = int32(v)
820809

821810
return nil
822811

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
834812
case *int16:
835813
*vv = int16(v)
836814

837815
return nil
838816

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
850817
case *int8:
851818
*vv = int8(v)
852819

853820
return nil
854821

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
866822
case *float64:
867823
*vv = float64(v)
868824

@@ -981,49 +937,16 @@ func (v int32Value) castTo(dst interface{}) error {
981937

982938
return nil
983939

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
995940
case *int:
996941
*vv = int(v)
997942

998943
return nil
999944

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
1011945
case *int32:
1012946
*vv = int32(v)
1013947

1014948
return nil
1015949

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
1027950
case *float64:
1028951
*vv = float64(v)
1029952

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

10801003
return nil
10811004

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
10931005
case *float64:
10941006
*vv = float64(v)
10951007

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)