Skip to content

Commit 8d008de

Browse files
authored
feat(bigtable): add "TypeUnspecified" to represent an unspecified type (#10820)
1 parent caa826c commit 8d008de

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

bigtable/type.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ func Equal(a, b Type) bool {
5656
return proto.Equal(a.proto(), b.proto())
5757
}
5858

59+
// TypeUnspecified represents the absence of a type.
60+
type TypeUnspecified struct{}
61+
62+
func (n TypeUnspecified) proto() *btapb.Type {
63+
return &btapb.Type{}
64+
}
65+
5966
type unknown[T interface{}] struct {
6067
wrapped *T
6168
}
@@ -240,7 +247,9 @@ func ProtoToType(pb *btapb.Type) Type {
240247
if pb == nil {
241248
return unknown[btapb.Type]{wrapped: nil}
242249
}
243-
250+
if pb.Kind == nil {
251+
return TypeUnspecified{}
252+
}
244253
switch t := pb.Kind.(type) {
245254
case *btapb.Type_Int64Type:
246255
return int64ProtoToType(t.Int64Type)

bigtable/type_test.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestNilChecks(t *testing.T) {
184184
if val, ok := ProtoToType(nil).(unknown[btapb.Type]); !ok {
185185
t.Errorf("got: %T, wanted unknown[btapb.Type]", val)
186186
}
187-
if val, ok := ProtoToType(&btapb.Type{}).(unknown[btapb.Type]); !ok {
187+
if val, ok := ProtoToType(&btapb.Type{}).(TypeUnspecified); !ok {
188188
t.Errorf("got: %T, wanted unknown[btapb.Type]", val)
189189
}
190190

@@ -221,3 +221,13 @@ func TestNilChecks(t *testing.T) {
221221
t.Errorf("got: %T, wanted unknown[btapb.Type]", val)
222222
}
223223
}
224+
225+
func TestTypeUnspecified(t *testing.T) {
226+
pb := &btapb.Type{}
227+
tpe := ProtoToType(pb)
228+
assertType(t, tpe, &btapb.Type{})
229+
expect := TypeUnspecified{}
230+
if tpe != expect {
231+
t.Errorf("got: %v, wanted: %v", tpe, expect)
232+
}
233+
}

0 commit comments

Comments
 (0)