Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bigtable): add "TypeUnspecified" to represent an unspecified type #10820

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bigtable/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ func Equal(a, b Type) bool {
return proto.Equal(a.proto(), b.proto())
}

// TypeUnspecified represents the absence of a type.
type TypeUnspecified struct{}

func (n TypeUnspecified) proto() *btapb.Type {
return &btapb.Type{}
}

type unknown[T interface{}] struct {
wrapped *T
}
Expand Down Expand Up @@ -240,7 +247,9 @@ func ProtoToType(pb *btapb.Type) Type {
if pb == nil {
return unknown[btapb.Type]{wrapped: nil}
}

if pb.Kind == nil {
return TypeUnspecified{}
}
switch t := pb.Kind.(type) {
case *btapb.Type_Int64Type:
return int64ProtoToType(t.Int64Type)
Expand Down
12 changes: 11 additions & 1 deletion bigtable/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestNilChecks(t *testing.T) {
if val, ok := ProtoToType(nil).(unknown[btapb.Type]); !ok {
t.Errorf("got: %T, wanted unknown[btapb.Type]", val)
}
if val, ok := ProtoToType(&btapb.Type{}).(unknown[btapb.Type]); !ok {
if val, ok := ProtoToType(&btapb.Type{}).(TypeUnspecified); !ok {
t.Errorf("got: %T, wanted unknown[btapb.Type]", val)
}

Expand Down Expand Up @@ -221,3 +221,13 @@ func TestNilChecks(t *testing.T) {
t.Errorf("got: %T, wanted unknown[btapb.Type]", val)
}
}

func TestTypeUnspecified(t *testing.T) {
pb := &btapb.Type{}
tpe := ProtoToType(pb)
assertType(t, tpe, &btapb.Type{})
expect := TypeUnspecified{}
if tpe != expect {
t.Errorf("got: %v, wanted: %v", tpe, expect)
}
}
Loading