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 string type to supported Bigtable type #10306

Merged
merged 11 commits into from
Jun 20, 2024
30 changes: 30 additions & 0 deletions bigtable/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,36 @@ func (bytes BytesType) proto() *btapb.Type {
return &btapb.Type{Kind: &btapb.Type_BytesType{BytesType: &btapb.Type_Bytes{Encoding: encoding}}}
}

// StringEncoding represents the encoding of a String.
type StringEncoding interface {
proto() *btapb.Type_String_Encoding
}

// StringUtf8Encoding represents a string with UTF-8 encoding.
type StringUtf8Encoding struct {
}

func (encoding StringUtf8Encoding) proto() *btapb.Type_String_Encoding {
return &btapb.Type_String_Encoding{
Encoding: &btapb.Type_String_Encoding_Utf8Raw_{},
}
}

// StringType represents a string
type StringType struct {
Encoding StringEncoding
}

func (str StringType) proto() *btapb.Type {
var encoding *btapb.Type_String_Encoding
if str.Encoding != nil {
encoding = str.Encoding.proto()
} else {
encoding = StringUtf8Encoding{}.proto()
}
return &btapb.Type{Kind: &btapb.Type_StringType{StringType: &btapb.Type_String{Encoding: encoding}}}
}

// Int64Encoding represents the encoding of an Int64 type.
type Int64Encoding interface {
proto() *btapb.Type_Int64_Encoding
Expand Down
17 changes: 17 additions & 0 deletions bigtable/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ func TestInt64Proto(t *testing.T) {
}
}

func TestStringProto(t *testing.T) {
want := &btapb.Type{
Kind: &btapb.Type_StringType{
StringType: &btapb.Type_String{
Encoding: &btapb.Type_String_Encoding{
Encoding: &btapb.Type_String_Encoding_Utf8Raw_{},
},
},
},
}

got := StringType{}.proto()
if !proto.Equal(got, want) {
t.Errorf("got type %v, want: %v", got, want)
}
}

func TestAggregateProto(t *testing.T) {
want := &btapb.Type{
Kind: &btapb.Type_AggregateType{
Expand Down
Loading