Skip to content

Commit

Permalink
feat(bigquery/storage/managedwriter/adapt): support proto3 presence (#…
Browse files Browse the repository at this point in the history
…6021)

This PR changes the normalizer to clear the proto3 optional presence
field in the FieldDescriptorProto. The backend can treat this case
as an instance of proto2 optional.

More background information: https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md
  • Loading branch information
shollyman authored May 19, 2022

Verified

This commit was signed with the committer’s verified signature. The key has been revoked.
eggplants haruna
1 parent e266aa8 commit 2984600
Showing 4 changed files with 173 additions and 67 deletions.
5 changes: 5 additions & 0 deletions bigquery/storage/managedwriter/adapt/protoconversion.go
Original file line number Diff line number Diff line change
@@ -311,6 +311,11 @@ func normalizeDescriptorInternal(in protoreflect.MessageDescriptor, visitedTypes
for i := 0; i < in.Fields().Len(); i++ {
inField := in.Fields().Get(i)
resultFDP := protodesc.ToFieldDescriptorProto(inField)
// Clear proto3 optional annotation, as the backend converter can
// treat this as a proto2 optional.
if resultFDP.Proto3Optional != nil {
resultFDP.Proto3Optional = nil
}
if resultFDP.OneofIndex != nil {
resultFDP.OneofIndex = nil
}
23 changes: 23 additions & 0 deletions bigquery/storage/managedwriter/adapt/protoconversion_test.go
Original file line number Diff line number Diff line change
@@ -621,6 +621,29 @@ func TestNormalizeDescriptor(t *testing.T) {
},
},
},
{
description: "WithProto3Optional",
in: (&testdata.SimpleMessageProto3WithOptional{}).ProtoReflect().Descriptor(),
want: &descriptorpb.DescriptorProto{
Name: proto.String("testdata_SimpleMessageProto3WithOptional"),
Field: []*descriptorpb.FieldDescriptorProto{
{
Name: proto.String("name"),
JsonName: proto.String("name"),
Number: proto.Int32(1),
Type: descriptorpb.FieldDescriptorProto_TYPE_STRING.Enum(),
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
},
{
Name: proto.String("value"),
JsonName: proto.String("value"),
Number: proto.Int32(2),
Type: descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(),
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
},
},
},
},
{
description: "WithExternalEnum",
in: (&testdata.ExternalEnumMessage{}).ProtoReflect().Descriptor(),
Loading

0 comments on commit 2984600

Please sign in to comment.