Skip to content

Commit 4287e4b

Browse files
authored
fix(bigquery): field descriptor proto name should not be lowercase (#8495)
1 parent b5000f6 commit 4287e4b

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

bigquery/storage/managedwriter/adapt/protoconversion.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ func storageSchemaToDescriptorInternal(inSchema *storagepb.TableSchema, scope st
286286
//
287287
// Messages are always nullable, and repeated fields are as well.
288288
func tableFieldSchemaToFieldDescriptorProto(field *storagepb.TableFieldSchema, idx int32, scope string, useProto3 bool) (*descriptorpb.FieldDescriptorProto, error) {
289-
290-
name := strings.ToLower(field.GetName())
289+
name := field.GetName()
291290
var fdp *descriptorpb.FieldDescriptorProto
292291

293292
if field.GetType() == storagepb.TableFieldSchema_STRUCT {

bigquery/storage/managedwriter/adapt/protoconversion_test.go

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,96 @@ func TestSchemaToProtoConversion(t *testing.T) {
192192
},
193193
},
194194
},
195+
{
196+
description: "nested-uppercase",
197+
bq: &storagepb.TableSchema{
198+
Fields: []*storagepb.TableFieldSchema{
199+
{Name: "recordID", Type: storagepb.TableFieldSchema_INT64, Mode: storagepb.TableFieldSchema_REQUIRED},
200+
{
201+
Name: "recordDetails",
202+
Type: storagepb.TableFieldSchema_STRUCT,
203+
Mode: storagepb.TableFieldSchema_REPEATED,
204+
Fields: []*storagepb.TableFieldSchema{
205+
{Name: "key", Type: storagepb.TableFieldSchema_STRING, Mode: storagepb.TableFieldSchema_REQUIRED},
206+
{Name: "value", Type: storagepb.TableFieldSchema_BYTES, Mode: storagepb.TableFieldSchema_NULLABLE},
207+
},
208+
},
209+
},
210+
},
211+
wantProto2: &descriptorpb.DescriptorProto{
212+
Name: proto.String("root"),
213+
Field: []*descriptorpb.FieldDescriptorProto{
214+
{
215+
Name: proto.String("recordID"),
216+
Number: proto.Int32(1),
217+
Type: descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(),
218+
Label: descriptorpb.FieldDescriptorProto_LABEL_REQUIRED.Enum(),
219+
},
220+
{
221+
Name: proto.String("recordDetails"),
222+
Number: proto.Int32(2),
223+
Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
224+
TypeName: proto.String(".root__recordDetails"),
225+
Label: descriptorpb.FieldDescriptorProto_LABEL_REPEATED.Enum(),
226+
},
227+
},
228+
},
229+
wantProto2Normalized: &descriptorpb.DescriptorProto{
230+
Name: proto.String("root"),
231+
Field: []*descriptorpb.FieldDescriptorProto{
232+
{
233+
Name: proto.String("recordID"),
234+
Number: proto.Int32(1),
235+
Type: descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(),
236+
Label: descriptorpb.FieldDescriptorProto_LABEL_REQUIRED.Enum(),
237+
},
238+
{
239+
Name: proto.String("recordDetails"),
240+
Number: proto.Int32(2),
241+
Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
242+
TypeName: proto.String("root__recordDetails"),
243+
Label: descriptorpb.FieldDescriptorProto_LABEL_REPEATED.Enum(),
244+
},
245+
},
246+
NestedType: []*descriptorpb.DescriptorProto{
247+
{
248+
Name: proto.String("root__recordDetails"),
249+
Field: []*descriptorpb.FieldDescriptorProto{
250+
{
251+
Name: proto.String("key"),
252+
Number: proto.Int32(1),
253+
Type: descriptorpb.FieldDescriptorProto_TYPE_STRING.Enum(),
254+
Label: descriptorpb.FieldDescriptorProto_LABEL_REQUIRED.Enum(),
255+
},
256+
{
257+
Name: proto.String("value"),
258+
Number: proto.Int32(2),
259+
Type: descriptorpb.FieldDescriptorProto_TYPE_BYTES.Enum(),
260+
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
261+
},
262+
},
263+
},
264+
},
265+
},
266+
wantProto3: &descriptorpb.DescriptorProto{
267+
Name: proto.String("root"),
268+
Field: []*descriptorpb.FieldDescriptorProto{
269+
{
270+
Name: proto.String("recordID"),
271+
Number: proto.Int32(1),
272+
Type: descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(),
273+
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
274+
},
275+
{
276+
Name: proto.String("recordDetails"),
277+
Number: proto.Int32(2),
278+
Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
279+
TypeName: proto.String(".root__recordDetails"),
280+
Label: descriptorpb.FieldDescriptorProto_LABEL_REPEATED.Enum(),
281+
},
282+
},
283+
},
284+
},
195285
{
196286
// We expect to re-use the submessage twice, as the schema contains two identical structs.
197287
description: "nested w/duplicate submessage",
@@ -510,7 +600,7 @@ func TestSchemaToProtoConversion(t *testing.T) {
510600
if tc.wantProto3 != nil {
511601
gotDP := protodesc.ToDescriptorProto(mDesc)
512602
if diff := cmp.Diff(gotDP, tc.wantProto3, protocmp.Transform()); diff != "" {
513-
t.Errorf("%s proto2: -got, +want:\n%s", tc.description, diff)
603+
t.Errorf("%s proto3: -got, +want:\n%s", tc.description, diff)
514604
}
515605
}
516606
// Check the normalized case.

0 commit comments

Comments
 (0)