Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bool set to false is skipped during marshal #109

Open
jadn123 opened this issue Nov 4, 2021 · 0 comments
Open

bool set to false is skipped during marshal #109

jadn123 opened this issue Nov 4, 2021 · 0 comments

Comments

@jadn123
Copy link

jadn123 commented Nov 4, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant