From a01d1581e9cdd20214a6b0c5cf9d9e6d6703d5fb Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Tue, 10 Sep 2024 13:19:00 +0300 Subject: [PATCH 1/4] initial nullable value within parambuilder --- internal/params/optional.go | 100 +++++++++++++++---------------- internal/params/optional_test.go | 78 ++++++++++++++---------- internal/value/nullable.go | 17 ++++++ internal/value/value.go | 9 +++ table/types/value.go | 15 +++-- 5 files changed, 132 insertions(+), 87 deletions(-) diff --git a/internal/params/optional.go b/internal/params/optional.go index f5aa02efb..94aa7188b 100644 --- a/internal/params/optional.go +++ b/internal/params/optional.go @@ -27,152 +27,152 @@ func (b *optionalBuilder) EndOptional() Builder { return b.opt.parent } -func (p *optional) Text(v string) *optionalBuilder { - p.value = value.TextValue(v) +func (p *optional) Text(v *string) *optionalBuilder { + p.value = value.NullableTextValue(v) return &optionalBuilder{opt: p} } -func (p *optional) Bytes(v []byte) *optionalBuilder { - p.value = value.BytesValue(v) +func (p *optional) Bytes(v *[]byte) *optionalBuilder { + p.value = value.NullableBytesValue(v) return &optionalBuilder{opt: p} } -func (p *optional) Bool(v bool) *optionalBuilder { - p.value = value.BoolValue(v) +func (p *optional) Bool(v *bool) *optionalBuilder { + p.value = value.NullableBoolValue(v) return &optionalBuilder{opt: p} } -func (p *optional) Uint64(v uint64) *optionalBuilder { - p.value = value.Uint64Value(v) +func (p *optional) Uint64(v *uint64) *optionalBuilder { + p.value = value.NullableUint64Value(v) return &optionalBuilder{opt: p} } -func (p *optional) Int64(v int64) *optionalBuilder { - p.value = value.Int64Value(v) +func (p *optional) Int64(v *int64) *optionalBuilder { + p.value = value.NullableInt64Value(v) return &optionalBuilder{opt: p} } -func (p *optional) Uint32(v uint32) *optionalBuilder { - p.value = value.Uint32Value(v) +func (p *optional) Uint32(v *uint32) *optionalBuilder { + p.value = value.NullableUint32Value(v) return &optionalBuilder{opt: p} } -func (p *optional) Int32(v int32) *optionalBuilder { - p.value = value.Int32Value(v) +func (p *optional) Int32(v *int32) *optionalBuilder { + p.value = value.NullableInt32Value(v) return &optionalBuilder{opt: p} } -func (p *optional) Uint16(v uint16) *optionalBuilder { - p.value = value.Uint16Value(v) +func (p *optional) Uint16(v *uint16) *optionalBuilder { + p.value = value.NullableUint16Value(v) return &optionalBuilder{opt: p} } -func (p *optional) Int16(v int16) *optionalBuilder { - p.value = value.Int16Value(v) +func (p *optional) Int16(v *int16) *optionalBuilder { + p.value = value.NullableInt16Value(v) return &optionalBuilder{opt: p} } -func (p *optional) Uint8(v uint8) *optionalBuilder { - p.value = value.Uint8Value(v) +func (p *optional) Uint8(v *uint8) *optionalBuilder { + p.value = value.NullableUint8Value(v) return &optionalBuilder{opt: p} } -func (p *optional) Int8(v int8) *optionalBuilder { - p.value = value.Int8Value(v) +func (p *optional) Int8(v *int8) *optionalBuilder { + p.value = value.NullableInt8Value(v) return &optionalBuilder{opt: p} } -func (p *optional) Float(v float32) *optionalBuilder { - p.value = value.FloatValue(v) +func (p *optional) Float(v *float32) *optionalBuilder { + p.value = value.NullableFloatValue(v) return &optionalBuilder{opt: p} } -func (p *optional) Double(v float64) *optionalBuilder { - p.value = value.DoubleValue(v) +func (p *optional) Double(v *float64) *optionalBuilder { + p.value = value.NullableDoubleValue(v) return &optionalBuilder{opt: p} } -func (p *optional) Decimal(v [16]byte, precision, scale uint32) *optionalBuilder { - p.value = value.DecimalValue(v, precision, scale) +func (p *optional) Decimal(v *[16]byte, precision, scale uint32) *optionalBuilder { + p.value = value.NullableDecimalValue(v, precision, scale) return &optionalBuilder{opt: p} } -func (p *optional) Timestamp(v time.Time) *optionalBuilder { - p.value = value.TimestampValueFromTime(v) +func (p *optional) Timestamp(v *time.Time) *optionalBuilder { + p.value = value.NullableTimestampValueFromTime(v) return &optionalBuilder{opt: p} } -func (p *optional) Date(v time.Time) *optionalBuilder { - p.value = value.DateValueFromTime(v) +func (p *optional) Date(v *time.Time) *optionalBuilder { + p.value = value.NullableDateValueFromTime(v) return &optionalBuilder{opt: p} } -func (p *optional) Datetime(v time.Time) *optionalBuilder { - p.value = value.DatetimeValueFromTime(v) +func (p *optional) Datetime(v *time.Time) *optionalBuilder { + p.value = value.NullableDatetimeValueFromTime(v) return &optionalBuilder{opt: p} } -func (p *optional) Interval(v time.Duration) *optionalBuilder { - p.value = value.IntervalValueFromDuration(v) +func (p *optional) Interval(v *time.Duration) *optionalBuilder { + p.value = value.NullableIntervalValueFromDuration(v) return &optionalBuilder{opt: p} } -func (p *optional) JSON(v string) *optionalBuilder { - p.value = value.JSONValue(v) +func (p *optional) JSON(v *string) *optionalBuilder { + p.value = value.NullableJSONValue(v) return &optionalBuilder{opt: p} } -func (p *optional) JSONDocument(v string) *optionalBuilder { - p.value = value.JSONDocumentValue(v) +func (p *optional) JSONDocument(v *string) *optionalBuilder { + p.value = value.NullableJSONDocumentValue(v) return &optionalBuilder{opt: p} } -func (p *optional) YSON(v []byte) *optionalBuilder { - p.value = value.YSONValue(v) +func (p *optional) YSON(v *[]byte) *optionalBuilder { + p.value = value.NullableYSONValueFromBytes(v) return &optionalBuilder{opt: p} } -func (p *optional) UUID(v [16]byte) *optionalBuilder { - p.value = value.UUIDValue(v) +func (p *optional) UUID(v *[16]byte) *optionalBuilder { + p.value = value.NullableUUIDValue(v) return &optionalBuilder{opt: p} } -func (p *optional) TzDate(v time.Time) *optionalBuilder { - p.value = value.TzDateValueFromTime(v) +func (p *optional) TzDate(v *time.Time) *optionalBuilder { + p.value = value.NullableTzDateValueFromTime(v) return &optionalBuilder{opt: p} } -func (p *optional) TzTimestamp(v time.Time) *optionalBuilder { - p.value = value.TzTimestampValueFromTime(v) +func (p *optional) TzTimestamp(v *time.Time) *optionalBuilder { + p.value = value.NullableTzTimestampValueFromTime(v) return &optionalBuilder{opt: p} } -func (p *optional) TzDatetime(v time.Time) *optionalBuilder { - p.value = value.TzDatetimeValueFromTime(v) +func (p *optional) TzDatetime(v *time.Time) *optionalBuilder { + p.value = value.NullableTzDatetimeValueFromTime(v) return &optionalBuilder{opt: p} } diff --git a/internal/params/optional_test.go b/internal/params/optional_test.go index 0c21718a1..ff963ed86 100644 --- a/internal/params/optional_test.go +++ b/internal/params/optional_test.go @@ -25,37 +25,49 @@ func TestOptional(t *testing.T) { }{ { method: "Uint64", - args: []any{uint64(123)}, + args: []any{p(uint64(123))}, expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT64}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT64}, + }}}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Uint64Value{ - Uint64Value: 123, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 123, + }, + }, }, }, }, }, { method: "Int64", - args: []any{int64(123)}, + args: []any{p(int64(123))}, expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT64}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT64}, + }}}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Int64Value{ - Int64Value: 123, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Int64Value{ + Int64Value: 123, + }, + }, }, }, }, }, { method: "Uint32", - args: []any{uint32(123)}, + args: []any{p(uint32(123))}, expected: expected{ Type: &Ydb.Type{ @@ -70,7 +82,7 @@ func TestOptional(t *testing.T) { }, { method: "Int32", - args: []any{int32(123)}, + args: []any{p(int32(123))}, expected: expected{ Type: &Ydb.Type{ @@ -85,7 +97,7 @@ func TestOptional(t *testing.T) { }, { method: "Uint16", - args: []any{uint16(123)}, + args: []any{p(uint16(123))}, expected: expected{ Type: &Ydb.Type{ @@ -100,7 +112,7 @@ func TestOptional(t *testing.T) { }, { method: "Int16", - args: []any{int16(123)}, + args: []any{p(int16(123))}, expected: expected{ Type: &Ydb.Type{ @@ -115,7 +127,7 @@ func TestOptional(t *testing.T) { }, { method: "Uint8", - args: []any{uint8(123)}, + args: []any{p(uint8(123))}, expected: expected{ Type: &Ydb.Type{ @@ -130,7 +142,7 @@ func TestOptional(t *testing.T) { }, { method: "Int8", - args: []any{int8(123)}, + args: []any{p(int8(123))}, expected: expected{ Type: &Ydb.Type{ @@ -145,7 +157,7 @@ func TestOptional(t *testing.T) { }, { method: "Bool", - args: []any{true}, + args: []any{p(true)}, expected: expected{ Type: &Ydb.Type{ @@ -160,7 +172,7 @@ func TestOptional(t *testing.T) { }, { method: "Text", - args: []any{"test"}, + args: []any{p("test")}, expected: expected{ Type: &Ydb.Type{ @@ -175,7 +187,7 @@ func TestOptional(t *testing.T) { }, { method: "Bytes", - args: []any{[]byte("test")}, + args: []any{p([]byte("test"))}, expected: expected{ Type: &Ydb.Type{ @@ -190,7 +202,7 @@ func TestOptional(t *testing.T) { }, { method: "Float", - args: []any{float32(123)}, + args: []any{p(float32(123))}, expected: expected{ Type: &Ydb.Type{ @@ -205,7 +217,7 @@ func TestOptional(t *testing.T) { }, { method: "Double", - args: []any{float64(123)}, + args: []any{p(float64(123))}, expected: expected{ Type: &Ydb.Type{ @@ -220,7 +232,7 @@ func TestOptional(t *testing.T) { }, { method: "Interval", - args: []any{time.Second}, + args: []any{p(time.Second)}, expected: expected{ Type: &Ydb.Type{ @@ -235,7 +247,7 @@ func TestOptional(t *testing.T) { }, { method: "Datetime", - args: []any{time.Unix(123456789, 456)}, + args: []any{p(time.Unix(123456789, 456))}, expected: expected{ Type: &Ydb.Type{ @@ -250,7 +262,7 @@ func TestOptional(t *testing.T) { }, { method: "Date", - args: []any{time.Unix(123456789, 456)}, + args: []any{p(time.Unix(123456789, 456))}, expected: expected{ Type: &Ydb.Type{ @@ -265,7 +277,7 @@ func TestOptional(t *testing.T) { }, { method: "Timestamp", - args: []any{time.Unix(123456789, 456)}, + args: []any{p(time.Unix(123456789, 456))}, expected: expected{ Type: &Ydb.Type{ @@ -280,7 +292,7 @@ func TestOptional(t *testing.T) { }, { method: "Decimal", - args: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, uint32(22), uint32(9)}, + args: []any{p([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}), uint32(22), uint32(9)}, expected: expected{ Type: &Ydb.Type{ @@ -301,7 +313,7 @@ func TestOptional(t *testing.T) { }, { method: "JSON", - args: []any{`{"a": 1,"b": "B"}`}, + args: []any{p(`{"a": 1,"b": "B"}`)}, expected: expected{ Type: &Ydb.Type{ @@ -316,7 +328,7 @@ func TestOptional(t *testing.T) { }, { method: "JSONDocument", - args: []any{`{"a": 1,"b": "B"}`}, + args: []any{p(`{"a": 1,"b": "B"}`)}, expected: expected{ Type: &Ydb.Type{ @@ -331,7 +343,7 @@ func TestOptional(t *testing.T) { }, { method: "YSON", - args: []any{[]byte(`{"a": 1,"b": "B"}`)}, + args: []any{p([]byte(`{"a": 1,"b": "B"}`))}, expected: expected{ Type: &Ydb.Type{ @@ -346,7 +358,7 @@ func TestOptional(t *testing.T) { }, { method: "UUID", - args: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}}, + 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{ @@ -362,7 +374,7 @@ func TestOptional(t *testing.T) { }, { method: "TzDatetime", - args: []any{time.Unix(123456789, 456).UTC()}, + args: []any{p(time.Unix(123456789, 456).UTC())}, expected: expected{ Type: &Ydb.Type{ @@ -377,7 +389,7 @@ func TestOptional(t *testing.T) { }, { method: "TzDate", - args: []any{time.Unix(123456789, 456).UTC()}, + args: []any{p(time.Unix(123456789, 456).UTC())}, expected: expected{ Type: &Ydb.Type{ @@ -392,7 +404,7 @@ func TestOptional(t *testing.T) { }, { method: "TzTimestamp", - args: []any{time.Unix(123456789, 456).UTC()}, + args: []any{p(time.Unix(123456789, 456).UTC())}, expected: expected{ Type: &Ydb.Type{ @@ -434,3 +446,7 @@ func TestOptional(t *testing.T) { }) } } + +func p[T any](v T) *T { + return &v +} diff --git a/internal/value/nullable.go b/internal/value/nullable.go index 8a532d9e1..6f35e1752 100644 --- a/internal/value/nullable.go +++ b/internal/value/nullable.go @@ -2,6 +2,7 @@ package value import ( "fmt" + "math/big" "time" "github.com/ydb-platform/ydb-go-sdk/v3/internal/types" @@ -128,6 +129,22 @@ func NullableDatetimeValueFromTime(v *time.Time) Value { return OptionalValue(DatetimeValueFromTime(*v)) } +func NullableDecimalValue(v *[16]byte, precision, scale uint32) Value { + if v == nil { + return NullValue(types.NewDecimal(precision, scale)) + } else { + return OptionalValue(DecimalValue(*v, precision, scale)) + } +} + +func NullableDecimalValueFromBigInt(v *big.Int, precision, scale uint32) Value { + if v == nil { + return NullValue(types.NewDecimal(precision, scale)) + } else { + return OptionalValue(DecimalValueFromBigInt(v, precision, scale)) + } +} + func NullableTzDateValue(v *string) Value { if v == nil { return NullValue(types.TzDate) diff --git a/internal/value/value.go b/internal/value/value.go index 4a79400ea..c4c6b895a 100644 --- a/internal/value/value.go +++ b/internal/value/value.go @@ -545,6 +545,15 @@ func DecimalValueFromBigInt(v *big.Int, precision, scale uint32) *decimalValue { return DecimalValue(b, precision, scale) } +func DecimalValueFromString(str string, precision, scale uint32) (Value, error) { + bigI, err := decimal.Parse(str, precision, scale) + if err != nil { + return nil, err + } + + return DecimalValueFromBigInt(bigI, precision, scale), nil +} + func DecimalValue(v [16]byte, precision, scale uint32) *decimalValue { return &decimalValue{ value: v, diff --git a/table/types/value.go b/table/types/value.go index 88a653d52..e306e3ad4 100644 --- a/table/types/value.go +++ b/table/types/value.go @@ -190,12 +190,7 @@ func DecimalValueFromBigInt(v *big.Int, precision, scale uint32) Value { } func DecimalValueFromString(str string, precision, scale uint32) (Value, error) { - bigI, err := decimal.Parse(str, precision, scale) - if err != nil { - return nil, err - } - - return value.DecimalValueFromBigInt(bigI, precision, scale), nil + return value.DecimalValueFromString(str, precision, scale) } func TupleValue(vs ...Value) Value { @@ -316,6 +311,14 @@ func NullableDateValueFromTime(v *time.Time) Value { return value.NullableDateValueFromTime(v) } +func NullableDecimalValue(v *[16]byte, precision, scale uint32) Value { + return value.NullableDecimalValue(v, precision, scale) +} + +func NullableDecimalValueFromBigInt(v *big.Int, precision, scale uint32) Value { + return value.NullableDecimalValueFromBigInt(v, precision, scale) +} + func NullableDatetimeValue(v *uint32) Value { return value.NullableDatetimeValue(v) } From a55bb2f7a68909c05c93b83495ef6a9eebfa74a2 Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Wed, 18 Sep 2024 21:30:24 +0300 Subject: [PATCH 2/4] fix tests --- internal/params/optional_test.go | 342 ++++++++++++++++++++++++------- 1 file changed, 266 insertions(+), 76 deletions(-) diff --git a/internal/params/optional_test.go b/internal/params/optional_test.go index ff963ed86..3b1864d80 100644 --- a/internal/params/optional_test.go +++ b/internal/params/optional_test.go @@ -31,7 +31,9 @@ func TestOptional(t *testing.T) { Type: &Ydb.Type{ Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT64}, - }}}, + }, + }, + }, }, Value: &Ydb.Value{ Value: &Ydb.Value_NestedValue{ @@ -52,7 +54,9 @@ func TestOptional(t *testing.T) { Type: &Ydb.Type{ Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT64}, - }}}, + }, + }, + }, }, Value: &Ydb.Value{ Value: &Ydb.Value_NestedValue{ @@ -71,11 +75,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT32}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT32}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 123, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123, + }, + }, }, }, }, @@ -86,11 +98,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT32}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT32}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Int32Value{ - Int32Value: 123, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Int32Value{ + Int32Value: 123, + }, + }, }, }, }, @@ -101,11 +121,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT16}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT16}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 123, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123, + }, + }, }, }, }, @@ -116,11 +144,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT16}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT16}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Int32Value{ - Int32Value: 123, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Int32Value{ + Int32Value: 123, + }, + }, }, }, }, @@ -131,11 +167,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT8}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT8}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 123, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123, + }, + }, }, }, }, @@ -146,11 +190,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT8}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT8}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Int32Value{ - Int32Value: 123, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Int32Value{ + Int32Value: 123, + }, + }, }, }, }, @@ -161,11 +213,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_BOOL}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_BOOL}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_BoolValue{ - BoolValue: true, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_BoolValue{ + BoolValue: true, + }, + }, }, }, }, @@ -176,11 +236,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UTF8}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UTF8}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: "test", + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: "test", + }, + }, }, }, }, @@ -191,11 +259,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_STRING}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_STRING}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_BytesValue{ - BytesValue: []byte("test"), + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_BytesValue{ + BytesValue: []byte("test"), + }, + }, }, }, }, @@ -206,11 +282,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_FLOAT}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_FLOAT}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_FloatValue{ - FloatValue: float32(123), + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_FloatValue{ + FloatValue: float32(123), + }, + }, }, }, }, @@ -221,11 +305,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DOUBLE}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DOUBLE}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_DoubleValue{ - DoubleValue: float64(123), + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_DoubleValue{ + DoubleValue: float64(123), + }, + }, }, }, }, @@ -236,11 +328,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INTERVAL}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INTERVAL}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Int64Value{ - Int64Value: 1000000, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Int64Value{ + Int64Value: 1000000, + }, + }, }, }, }, @@ -251,11 +351,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATETIME}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATETIME}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 123456789, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123456789, + }, + }, }, }, }, @@ -266,11 +374,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATE}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATE}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 1428, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 1428, + }, + }, }, }, }, @@ -281,11 +397,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TIMESTAMP}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TIMESTAMP}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Uint64Value{ - Uint64Value: 123456789000000, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 123456789000000, + }, + }, }, }, }, @@ -296,17 +420,26 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_DecimalType{ - DecimalType: &Ydb.DecimalType{ - Precision: 22, - Scale: 9, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + + Type: &Ydb.Type_DecimalType{ + DecimalType: &Ydb.DecimalType{ + Precision: 22, + Scale: 9, + }, }, }, + }, + }, }, Value: &Ydb.Value{ - High_128: 72623859790382856, - Value: &Ydb.Value_Low_128{ - Low_128: 648519454493508870, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + High_128: 72623859790382856, + Value: &Ydb.Value_Low_128{ + Low_128: 648519454493508870, + }, + }, }, }, }, @@ -317,11 +450,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: `{"a": 1,"b": "B"}`, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: `{"a": 1,"b": "B"}`, + }, + }, }, }, }, @@ -332,11 +473,20 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON_DOCUMENT}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON_DOCUMENT}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: `{"a": 1,"b": "B"}`, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: `{"a": 1,"b": "B"}`, + }, + }, }, }, }, @@ -347,11 +497,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_YSON}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_YSON}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_BytesValue{ - BytesValue: []byte(`{"a": 1,"b": "B"}`), + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_BytesValue{ + BytesValue: []byte(`{"a": 1,"b": "B"}`), + }, + }, }, }, }, @@ -362,13 +520,21 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_Low_128{ - Low_128: 651345242494996240, + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_Low_128{ + Low_128: 651345242494996240, + }, + High_128: 72623859790382856, + }, }, - High_128: 72623859790382856, }, }, }, @@ -378,11 +544,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATETIME}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATETIME}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: "1973-11-29T21:33:09Z", + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: "1973-11-29T21:33:09Z", + }, + }, }, }, }, @@ -393,11 +567,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATE}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATE}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: "1973-11-29", + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: "1973-11-29", + }, + }, }, }, }, @@ -408,11 +590,19 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_TIMESTAMP}, + Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_TIMESTAMP}, + }, + }, + }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: "1973-11-29T21:33:09.000000Z", + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: "1973-11-29T21:33:09.000000Z", + }, + }, }, }, }, From dba4edc706a5003af76746dd0fc58ceccea7270e Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Wed, 18 Sep 2024 21:34:58 +0300 Subject: [PATCH 3/4] fixed changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d72a5ef80..a2ebb00ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Fixed bug in experimental api: `ydb.ParamsBuilder().Param().Optional()` receive pointer and really produce optional value. + ## v3.80.8 * Added `ydb.WithLazyTx(bool)` option for create lazy transactions on `query.Session.Begin` call * Added initial experimental topic and cdc-helpers, see examples in [tests/integration/topic_helpers_test.go](https://github.com/ydb-platform/ydb-go-sdk/blob/master/tests/integration/topic_helpers_test.go) From bc541e0a0e98e3d94bc6b7108b853862d8cd759e Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Wed, 18 Sep 2024 21:43:30 +0300 Subject: [PATCH 4/4] fix linter --- internal/params/optional_test.go | 258 ++++++++++++++++++------------- internal/value/nullable.go | 8 +- 2 files changed, 157 insertions(+), 109 deletions(-) diff --git a/internal/params/optional_test.go b/internal/params/optional_test.go index 3b1864d80..f199742ce 100644 --- a/internal/params/optional_test.go +++ b/internal/params/optional_test.go @@ -29,10 +29,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT64}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT64}, + }, + }, }, }, Value: &Ydb.Value{ @@ -52,10 +54,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT64}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT64}, + }, + }, }, }, Value: &Ydb.Value{ @@ -75,10 +79,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT32}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT32}, + }, + }, }, }, Value: &Ydb.Value{ @@ -98,10 +104,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT32}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT32}, + }, + }, }, }, Value: &Ydb.Value{ @@ -121,10 +129,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT16}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT16}, + }, + }, }, }, Value: &Ydb.Value{ @@ -144,10 +154,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT16}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT16}, + }, + }, }, }, Value: &Ydb.Value{ @@ -167,10 +179,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT8}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT8}, + }, + }, }, }, Value: &Ydb.Value{ @@ -190,10 +204,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT8}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT8}, + }, + }, }, }, Value: &Ydb.Value{ @@ -213,10 +229,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_BOOL}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_BOOL}, + }, + }, }, }, Value: &Ydb.Value{ @@ -236,10 +254,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UTF8}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UTF8}, + }, + }, }, }, Value: &Ydb.Value{ @@ -259,10 +279,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_STRING}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_STRING}, + }, + }, }, }, Value: &Ydb.Value{ @@ -282,10 +304,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_FLOAT}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_FLOAT}, + }, + }, }, }, Value: &Ydb.Value{ @@ -305,10 +329,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DOUBLE}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DOUBLE}, + }, + }, }, }, Value: &Ydb.Value{ @@ -328,10 +354,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INTERVAL}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INTERVAL}, + }, + }, }, }, Value: &Ydb.Value{ @@ -351,10 +379,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATETIME}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATETIME}, + }, + }, }, }, Value: &Ydb.Value{ @@ -374,10 +404,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATE}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATE}, + }, + }, }, }, Value: &Ydb.Value{ @@ -397,10 +429,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TIMESTAMP}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TIMESTAMP}, + }, + }, }, }, Value: &Ydb.Value{ @@ -420,17 +454,18 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - - Type: &Ydb.Type_DecimalType{ - DecimalType: &Ydb.DecimalType{ - Precision: 22, - Scale: 9, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_DecimalType{ + DecimalType: &Ydb.DecimalType{ + Precision: 22, + Scale: 9, + }, + }, }, }, }, - }, - }, }, Value: &Ydb.Value{ Value: &Ydb.Value_NestedValue{ @@ -450,10 +485,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON}, + }, + }, }, }, Value: &Ydb.Value{ @@ -473,11 +510,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON_DOCUMENT}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON_DOCUMENT}, + }, + }, }, }, Value: &Ydb.Value{ @@ -497,10 +535,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_YSON}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_YSON}, + }, + }, }, }, Value: &Ydb.Value{ @@ -520,10 +560,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, + }, + }, }, }, Value: &Ydb.Value{ @@ -544,10 +586,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATETIME}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATETIME}, + }, + }, }, }, Value: &Ydb.Value{ @@ -567,10 +611,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATE}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATE}, + }, + }, }, }, Value: &Ydb.Value{ @@ -590,10 +636,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_TIMESTAMP}, - }, - }, + Type: &Ydb.Type_OptionalType{ + OptionalType: &Ydb.OptionalType{ + Item: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_TIMESTAMP}, + }, + }, }, }, Value: &Ydb.Value{ diff --git a/internal/value/nullable.go b/internal/value/nullable.go index 6f35e1752..babf9a24a 100644 --- a/internal/value/nullable.go +++ b/internal/value/nullable.go @@ -132,17 +132,17 @@ func NullableDatetimeValueFromTime(v *time.Time) Value { func NullableDecimalValue(v *[16]byte, precision, scale uint32) Value { if v == nil { return NullValue(types.NewDecimal(precision, scale)) - } else { - return OptionalValue(DecimalValue(*v, precision, scale)) } + + return OptionalValue(DecimalValue(*v, precision, scale)) } func NullableDecimalValueFromBigInt(v *big.Int, precision, scale uint32) Value { if v == nil { return NullValue(types.NewDecimal(precision, scale)) - } else { - return OptionalValue(DecimalValueFromBigInt(v, precision, scale)) } + + return OptionalValue(DecimalValueFromBigInt(v, precision, scale)) } func NullableTzDateValue(v *string) Value {