-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 column family type to FamilyInfo in TableInfo #10182
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,24 @@ limitations under the License. | |
|
||
package bigtable | ||
|
||
import btapb "google.golang.org/genproto/googleapis/bigtable/admin/v2" | ||
import ( | ||
btapb "google.golang.org/genproto/googleapis/bigtable/admin/v2" | ||
) | ||
|
||
// Type wraps the protobuf representation of a type. See the protobuf definition | ||
// for more details on types. | ||
type Type interface { | ||
proto() *btapb.Type | ||
} | ||
|
||
type unknown[T interface{}] struct { | ||
wrapped *T | ||
} | ||
|
||
func (u unknown[T]) proto() *T { | ||
return u.wrapped | ||
} | ||
|
||
// BytesEncoding represents the encoding of a Bytes type. | ||
type BytesEncoding interface { | ||
proto() *btapb.Type_Bytes_Encoding | ||
|
@@ -112,6 +122,14 @@ func (sum SumAggregator) fillProto(proto *btapb.Type_Aggregate) { | |
proto.Aggregator = &btapb.Type_Aggregate_Sum_{Sum: &btapb.Type_Aggregate_Sum{}} | ||
} | ||
|
||
type unknownAggregator struct { | ||
wrapped *btapb.Type_Aggregate | ||
} | ||
|
||
func (ua unknownAggregator) fillProto(proto *btapb.Type_Aggregate) { | ||
proto.Aggregator = ua.wrapped.Aggregator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pointer nil check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. having basically no experience writing go, what am I supposed to do if its nil? |
||
} | ||
|
||
// AggregateType represents an aggregate. See types.proto for more details | ||
// on aggregate types. | ||
type AggregateType struct { | ||
|
@@ -127,3 +145,59 @@ func (agg AggregateType) proto() *btapb.Type { | |
agg.Aggregator.fillProto(protoAgg) | ||
return &btapb.Type{Kind: &btapb.Type_AggregateType{AggregateType: protoAgg}} | ||
} | ||
|
||
func protoToType(pb *btapb.Type) Type { | ||
if pb == nil { | ||
return nil | ||
} | ||
|
||
switch t := pb.Kind.(type) { | ||
case *btapb.Type_Int64Type: | ||
return int64ProtoToType(t.Int64Type) | ||
case *btapb.Type_BytesType: | ||
return bytesProtoToType(t.BytesType) | ||
case *btapb.Type_AggregateType: | ||
return aggregateProtoToType(t.AggregateType) | ||
default: | ||
return unknown[btapb.Type]{wrapped: pb} | ||
} | ||
} | ||
|
||
func bytesEncodingProtoToType(be *btapb.Type_Bytes_Encoding) BytesEncoding { | ||
switch be.Encoding.(type) { | ||
case *btapb.Type_Bytes_Encoding_Raw_: | ||
return RawBytesEncoding{} | ||
default: | ||
return unknown[btapb.Type_Bytes_Encoding]{wrapped: be} | ||
} | ||
} | ||
|
||
func bytesProtoToType(b *btapb.Type_Bytes) BytesType { | ||
return BytesType{Encoding: bytesEncodingProtoToType(b.Encoding)} | ||
} | ||
|
||
func int64EncodingProtoToEncoding(ie *btapb.Type_Int64_Encoding) Int64Encoding { | ||
switch e := ie.Encoding.(type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nil checks missing on ie and ie.encoding |
||
case *btapb.Type_Int64_Encoding_BigEndianBytes_: | ||
return BigEndianBytesEncoding{Bytes: bytesProtoToType(e.BigEndianBytes.BytesType)} | ||
default: | ||
return unknown[btapb.Type_Int64_Encoding]{wrapped: ie} | ||
} | ||
} | ||
|
||
func int64ProtoToType(i *btapb.Type_Int64) Type { | ||
return Int64Type{Encoding: int64EncodingProtoToEncoding(i.Encoding)} | ||
} | ||
|
||
func aggregateProtoToType(agg *btapb.Type_Aggregate) Type { | ||
it := protoToType(agg.InputType) | ||
|
||
var aggregator Aggregator | ||
switch agg.Aggregator.(type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nil checks missing on agg and agg.Aggregator |
||
case *btapb.Type_Aggregate_Sum_: | ||
aggregator = SumAggregator{} | ||
default: | ||
aggregator = unknownAggregator{wrapped: agg} | ||
} | ||
return AggregateType{Input: it, Aggregator: aggregator} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add nil checks wherever needed