If you have a bool field in the proto.Message and this is set to false it will not be part of the output map[string]bigquery.Value during marshalling. This means that when inserting the data into BigQuery this column will get the value null.
I think null would be fine if the type was the wrapper BoolValue but for bool it should resolve to false in the end.
I modified the existing test in example_test.go
func TestMarshal(t *testing.T) {
msg := &library.Book{
Name: "publishers/123/books/456",
Author: "P.L. Travers",
Title: "Mary Poppins",
Read: false,
}
row, err := protobq.Marshal(msg)
if err != nil {
// TODO: Handle error.
}
expected := map[string]bigquery.Value{
"name": "publishers/123/books/456",
"author": "P.L. Travers",
"title": "Mary Poppins",
"read": false,
}
fmt.Println("Expected:", expected)
fmt.Println("Got:", row)
fmt.Println("Equal:", cmp.Equal(expected, row))
}
Output
Expected: map[author:P.L. Travers name:publishers/123/books/456 read:false title:Mary Poppins]
Got: map[author:P.L. Travers name:publishers/123/books/456 title:Mary Poppins]
Equal: false
I can't find any MarshalOptions to control this behaviour.
If you have a
boolfield in theproto.Messageand this is set tofalseit will not be part of the outputmap[string]bigquery.Valueduring marshalling. This means that when inserting the data into BigQuery this column will get the valuenull.I think
nullwould be fine if the type was the wrapperBoolValuebut forboolit should resolve tofalsein the end.I modified the existing test in
example_test.goOutput
I can't find any
MarshalOptionsto control this behaviour.