Skip to content

Commit a9f3d19

Browse files
committed
added tests for raw ydb value
1 parent e0bbf8a commit a9f3d19

File tree

4 files changed

+98
-6
lines changed

4 files changed

+98
-6
lines changed

internal/types/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,11 +966,13 @@ type protobufType struct {
966966
}
967967

968968
func (v protobufType) Yql() string {
969-
return fmt.Sprintf("protobufType(%s)", v.pb.String())
969+
return FromYDB([]*Ydb.Type{
970+
v.pb,
971+
})[0].Yql()
970972
}
971973

972974
func (v protobufType) String() string {
973-
return fmt.Sprintf("protobufType(%s)", v.pb.String())
975+
return v.Yql()
974976
}
975977

976978
func (v protobufType) ToYDB(a *allocator.Allocator) *Ydb.Type {

internal/types/types_test.go

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

66
"github.com/stretchr/testify/require"
7+
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
78

89
"github.com/ydb-platform/ydb-go-sdk/v3/internal/pg"
910
)
@@ -273,11 +274,40 @@ func TestTypeToString(t *testing.T) {
273274
t: PgType{OID: pg.OIDUnknown},
274275
s: "PgType(705)",
275276
},
277+
{
278+
t: FromProtobuf(&Ydb.Type{
279+
Type: &Ydb.Type_VariantType{
280+
VariantType: &Ydb.VariantType{
281+
Type: &Ydb.VariantType_StructItems{
282+
StructItems: &Ydb.StructType{
283+
Members: []*Ydb.StructMember{
284+
{
285+
Name: "a",
286+
Type: &Ydb.Type{
287+
Type: &Ydb.Type_TypeId{
288+
TypeId: Ydb.Type_BOOL,
289+
},
290+
},
291+
},
292+
{
293+
Name: "a",
294+
Type: &Ydb.Type{
295+
Type: &Ydb.Type_TypeId{
296+
TypeId: Ydb.Type_FLOAT,
297+
},
298+
},
299+
},
300+
},
301+
},
302+
},
303+
},
304+
},
305+
}),
306+
s: "Variant<'a':Bool,'a':Float>",
307+
},
276308
} {
277309
t.Run(tt.s, func(t *testing.T) {
278-
if got := tt.t.Yql(); got != tt.s {
279-
t.Errorf("s representations not equals:\n\n - got: %s\n\n - want: %s", got, tt.s)
280-
}
310+
require.Equal(t, tt.s, tt.t.Yql())
281311
})
282312
}
283313
}

internal/value/value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2776,7 +2776,7 @@ func (v protobufValue) Type() types.Type {
27762776
}
27772777

27782778
func (v protobufValue) Yql() string {
2779-
return fmt.Sprintf("protobufValue(%s)", v.pb.String())
2779+
return FromYDB(v.pb.GetType(), v.pb.GetValue()).Yql()
27802780
}
27812781

27822782
func (v protobufValue) castTo(dst any) error {

internal/value/value_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/stretchr/testify/require"
13+
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
1314
"google.golang.org/protobuf/proto"
1415

1516
"github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator"
@@ -504,8 +505,67 @@ func TestValueYql(t *testing.T) {
504505
value: PgValue(pg.OIDUnknown, "123"),
505506
literal: `PgConst("123", PgType(705))`,
506507
},
508+
{
509+
value: FromProtobuf(&Ydb.TypedValue{
510+
Type: &Ydb.Type{
511+
Type: &Ydb.Type_TupleType{
512+
TupleType: &Ydb.TupleType{
513+
Elements: []*Ydb.Type{
514+
{
515+
Type: &Ydb.Type_TypeId{
516+
TypeId: Ydb.Type_INT32,
517+
},
518+
},
519+
{
520+
Type: &Ydb.Type_TypeId{
521+
TypeId: Ydb.Type_INT64,
522+
},
523+
},
524+
{
525+
Type: &Ydb.Type_TypeId{
526+
TypeId: Ydb.Type_FLOAT,
527+
},
528+
},
529+
{
530+
Type: &Ydb.Type_TypeId{
531+
TypeId: Ydb.Type_UTF8,
532+
},
533+
},
534+
},
535+
},
536+
},
537+
},
538+
Value: &Ydb.Value{
539+
Items: []*Ydb.Value{
540+
{
541+
Value: &Ydb.Value_Int32Value{
542+
Int32Value: 0,
543+
},
544+
},
545+
{
546+
Value: &Ydb.Value_Int64Value{
547+
Int64Value: 1,
548+
},
549+
},
550+
{
551+
Value: &Ydb.Value_FloatValue{
552+
FloatValue: 2,
553+
},
554+
},
555+
{
556+
Value: &Ydb.Value_TextValue{
557+
TextValue: "3",
558+
},
559+
},
560+
},
561+
},
562+
}),
563+
literal: `(0,1l,Float("2"),"3"u)`,
564+
},
507565
} {
508566
t.Run(strconv.Itoa(i)+"."+tt.literal, func(t *testing.T) {
567+
pb := tt.value.toYDB(allocator.New())
568+
fmt.Println(pb)
509569
require.Equal(t, tt.literal, tt.value.Yql())
510570
})
511571
}

0 commit comments

Comments
 (0)