Skip to content

Commit

Permalink
testing(bigquery/storage/managedwriter): add a range type test (#9676)
Browse files Browse the repository at this point in the history
* testing(bigquery/storage/managedwriter): add a range type test

This PR is minimal, but does validate we can specify a range schema, and
send a proto message containing a range value without error.

Towards #9017
  • Loading branch information
shollyman authored Apr 10, 2024
1 parent df14232 commit d6ee40c
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 115 deletions.
27 changes: 27 additions & 0 deletions bigquery/storage/managedwriter/adapt/protoconversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,14 @@ func TestNormalizeDescriptor(t *testing.T) {
Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
},
{
Name: proto.String("range_type"),
JsonName: proto.String("rangeType"),
Number: proto.Int32(3),
TypeName: proto.String("testdata_RangeTypeTimestamp"),
Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
},
},
NestedType: []*descriptorpb.DescriptorProto{
{
Expand Down Expand Up @@ -1069,6 +1077,25 @@ func TestNormalizeDescriptor(t *testing.T) {
},
},
},
{
Name: proto.String("testdata_RangeTypeTimestamp"),
Field: []*descriptorpb.FieldDescriptorProto{
{
Name: proto.String("start"),
JsonName: proto.String("start"),
Number: proto.Int32(1),
Type: descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(),
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
},
{
Name: proto.String("end"),
JsonName: proto.String("end"),
Number: proto.Int32(2),
Type: descriptorpb.FieldDescriptorProto_TYPE_INT64.Enum(),
Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
},
},
},
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions bigquery/storage/managedwriter/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,9 @@ func TestIntegration_ProtoNormalization(t *testing.T) {
InnerType: &testdata.InnerType{
Value: []string{"top"},
},
RangeType: &testdata.RangeTypeTimestamp{
End: proto.Int64(time.Now().UnixNano()),
},
}
b, err := proto.Marshal(mesg)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions bigquery/storage/managedwriter/testdata/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ var (
{Name: "value", Type: bigquery.StringFieldType, Repeated: true},
},
},
{
// range is a compound representation, but not quite a struct.
Name: "range_type",
Type: bigquery.RangeFieldType,
RangeElementType: &bigquery.RangeElementType{
Type: bigquery.TimestampFieldType,
},
},
}

// We currently follow proto2 rules here, hence the well known types getting treated as records.
Expand Down
Loading

0 comments on commit d6ee40c

Please sign in to comment.