From 4287e4bed40e69203ddb55bd754e3adbf269ba9e Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 29 Aug 2023 13:43:04 -0400 Subject: [PATCH] fix(bigquery): field descriptor proto name should not be lowercase (#8495) --- .../managedwriter/adapt/protoconversion.go | 3 +- .../adapt/protoconversion_test.go | 92 ++++++++++++++++++- 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/bigquery/storage/managedwriter/adapt/protoconversion.go b/bigquery/storage/managedwriter/adapt/protoconversion.go index 808dbade3b61..997a7edd1503 100644 --- a/bigquery/storage/managedwriter/adapt/protoconversion.go +++ b/bigquery/storage/managedwriter/adapt/protoconversion.go @@ -286,8 +286,7 @@ func storageSchemaToDescriptorInternal(inSchema *storagepb.TableSchema, scope st // // Messages are always nullable, and repeated fields are as well. func tableFieldSchemaToFieldDescriptorProto(field *storagepb.TableFieldSchema, idx int32, scope string, useProto3 bool) (*descriptorpb.FieldDescriptorProto, error) { - - name := strings.ToLower(field.GetName()) + name := field.GetName() var fdp *descriptorpb.FieldDescriptorProto if field.GetType() == storagepb.TableFieldSchema_STRUCT { diff --git a/bigquery/storage/managedwriter/adapt/protoconversion_test.go b/bigquery/storage/managedwriter/adapt/protoconversion_test.go index 758eaaa10300..a21ce16ff96e 100644 --- a/bigquery/storage/managedwriter/adapt/protoconversion_test.go +++ b/bigquery/storage/managedwriter/adapt/protoconversion_test.go @@ -192,6 +192,96 @@ func TestSchemaToProtoConversion(t *testing.T) { }, }, }, + { + description: "nested-uppercase", + bq: &storagepb.TableSchema{ + Fields: []*storagepb.TableFieldSchema{ + {Name: "recordID", Type: storagepb.TableFieldSchema_INT64, Mode: storagepb.TableFieldSchema_REQUIRED}, + { + Name: "recordDetails", + Type: storagepb.TableFieldSchema_STRUCT, + Mode: storagepb.TableFieldSchema_REPEATED, + Fields: []*storagepb.TableFieldSchema{ + {Name: "key", Type: storagepb.TableFieldSchema_STRING, Mode: storagepb.TableFieldSchema_REQUIRED}, + {Name: "value", Type: storagepb.TableFieldSchema_BYTES, Mode: storagepb.TableFieldSchema_NULLABLE}, + }, + }, + }, + }, + wantProto2: &descriptorpb.DescriptorProto{ + Name: proto.String("root"), + Field: []*descriptorpb.FieldDescriptorProto{ + { + Name: proto.String("recordID"), + Number: proto.Int32(1), + Type: descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(), + Label: descriptorpb.FieldDescriptorProto_LABEL_REQUIRED.Enum(), + }, + { + Name: proto.String("recordDetails"), + Number: proto.Int32(2), + Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(), + TypeName: proto.String(".root__recordDetails"), + Label: descriptorpb.FieldDescriptorProto_LABEL_REPEATED.Enum(), + }, + }, + }, + wantProto2Normalized: &descriptorpb.DescriptorProto{ + Name: proto.String("root"), + Field: []*descriptorpb.FieldDescriptorProto{ + { + Name: proto.String("recordID"), + Number: proto.Int32(1), + Type: descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(), + Label: descriptorpb.FieldDescriptorProto_LABEL_REQUIRED.Enum(), + }, + { + Name: proto.String("recordDetails"), + Number: proto.Int32(2), + Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(), + TypeName: proto.String("root__recordDetails"), + Label: descriptorpb.FieldDescriptorProto_LABEL_REPEATED.Enum(), + }, + }, + NestedType: []*descriptorpb.DescriptorProto{ + { + Name: proto.String("root__recordDetails"), + Field: []*descriptorpb.FieldDescriptorProto{ + { + Name: proto.String("key"), + Number: proto.Int32(1), + Type: descriptorpb.FieldDescriptorProto_TYPE_STRING.Enum(), + Label: descriptorpb.FieldDescriptorProto_LABEL_REQUIRED.Enum(), + }, + { + Name: proto.String("value"), + Number: proto.Int32(2), + Type: descriptorpb.FieldDescriptorProto_TYPE_BYTES.Enum(), + Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), + }, + }, + }, + }, + }, + wantProto3: &descriptorpb.DescriptorProto{ + Name: proto.String("root"), + Field: []*descriptorpb.FieldDescriptorProto{ + { + Name: proto.String("recordID"), + Number: proto.Int32(1), + Type: descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(), + Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), + }, + { + Name: proto.String("recordDetails"), + Number: proto.Int32(2), + Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(), + TypeName: proto.String(".root__recordDetails"), + Label: descriptorpb.FieldDescriptorProto_LABEL_REPEATED.Enum(), + }, + }, + }, + }, { // We expect to re-use the submessage twice, as the schema contains two identical structs. description: "nested w/duplicate submessage", @@ -510,7 +600,7 @@ func TestSchemaToProtoConversion(t *testing.T) { if tc.wantProto3 != nil { gotDP := protodesc.ToDescriptorProto(mDesc) if diff := cmp.Diff(gotDP, tc.wantProto3, protocmp.Transform()); diff != "" { - t.Errorf("%s proto2: -got, +want:\n%s", tc.description, diff) + t.Errorf("%s proto3: -got, +want:\n%s", tc.description, diff) } } // Check the normalized case.