feat(spanner): add support for handling null value in Proto columns#6954
Conversation
spanner/value.go
Outdated
| } | ||
|
|
||
| // MarshalJSON implements json.Marshaler.MarshalJSON for NullProto. | ||
| func (n NullProto) MarshalJSON() ([]byte, error) { |
There was a problem hiding this comment.
Could you please help me understand when and how MarshalJSON is used?
There was a problem hiding this comment.
MarshalJSON() converts a custom type (in this case NullProto) defined in client library to a []byte. These are few methods that are exposed to users and it is followed as a convention for every custom type in Go client library.
There was a problem hiding this comment.
How is the user expected to use the returned []byte? Is it for debugging only?
There was a problem hiding this comment.
Could you please help me understand when and how MarshalJSON is used?
We implement the MarshalJSON() and UnmarshalJSON() methods of Marshaler and Unmarshaler interfaces that belongs to the json package in golang. This is to provide the functionality of encoding custom types NullProtoMessage and NullProtoEnum into a JSON string and decoding JSON string into NullProtoMessage and NullProtoEnum.
How is the user expected to use the returned []byte?
Usage:
json.Marshal method can be used to encode a NullProtoMessage and NullProtoEnum into a JSON string.
json.Unmarshal method can be used to decode a JSON string into NullProtoMessage and NullProtoEnum.
As NullProtoMessage and NullProtoEnum are custom types we have to implement the above interfaces for the encode and decode to work as expected.
Added tests for these methods.
There was a problem hiding this comment.
Why do we need to encode and decode json?
olavloite
left a comment
There was a problem hiding this comment.
I'm not familiar enough with proto columns to know whether all of this makes sense or not, so I will have to defer to others for that. I've left a couple of more generic comments.
spanner/value.go
Outdated
| } | ||
|
|
||
| // MarshalJSON implements json.Marshaler.MarshalJSON for NullProto. | ||
| func (n NullProto) MarshalJSON() ([]byte, error) { |
There was a problem hiding this comment.
How is the user expected to use the returned []byte? Is it for debugging only?
Shua1
left a comment
There was a problem hiding this comment.
It's a bit hard to imagine the impact of this change on how users would use it. Let's proceed to see the dedicated integration tests and samples. Do we have issue tracking for them?
olavloite
left a comment
There was a problem hiding this comment.
LGTM, with some minor nits on comments and an error message
As golang maintains a seperate repository for samples and its integration tests, I will be raising a PR for the dedicated samples and integration tests for proto columns. The draft PR for these changes can be found here - PR-2754 |
* feat(spanner): add support for Proto Columns (#6886) * feat(spanner): Adding support for Proto Message and Proto Enum * feat(spanner): Add license header to new files * code refactoring and additional checks * nit: code changes * go.mod update to prevent failing builds * go.mod update to prevent failing builds * go.mod and build_samples.sh update to prevent failing builds * revert back grpc version * revert back changes * Using standard Singers example, refactoring redundant code * code and proto refactoring * Add proto_type_fqn for Proto Message and Proto Enum * code refactoring * go mod tidy: go.mod and go.sum version updates * add changes to support compatibility between Int64 and Enum & compatibility between Bytes and Proto * Revert "go mod tidy: go.mod and go.sum version updates" This reverts commit 484b00c. * add Integration Tests for Proto Message, Proto Enum, compatibility tests * code refactoring * code refactoring * add unit tests for nil proto types * Add error when nil proto message or nil enum is passed * feat(spanner): add support for handling null value in Proto columns (#6954) * feat(spanner): add support for handling null value in Proto columns * code refactor: get protoTypeFqn from user defined nil types * code refactoring * code refactoring * code refactoring * code refactoring * Add tests for MarshalJSON and UnmarshalJSON methods * refactoring test file * code refactoring * feat(spanner): add support for Array of Proto columns (#7014) * feat(spanner): add support for array of proto columns * refactoring comments and added negative test cases while reading array of protos * change decoding logic of handling array of proto columns * feat(spanner): add support for handling null values in array of proto columns (#7042) * feat(spanner): add support for handling null values in Array of Proto Columns * add comments for code readability * nit: change in error message * feat(spanner): Modify configuration for integration test and add license header (#7059) * feat(spanner): update go-genproto dependency (#7066) * feat(spanner): support for enum columns as keys, index and integration tests (#7091) * feat(spanner): support for proto columns as primary key and tests for parameterized queries, primary key and indexes * feat(spanner): close read-only transaction to prevent session leak * feat(spanner): update table schema to have GPK on proto field * feat(spanner): add proto changes to support proto columns feature * feat(spanner): remove gen-proto dep overwrite for proto column support * feat(spanner): remove gen-proto dep overwrite from kokoro build * feat(spanner): reset array of proto, enum when null from database (#7176) * feat(spanner): reset array of proto, enum when null from database * feat(spanner): fix license header to fix vet.sh build * feat(spanner): fix proto generated file to fix vet.sh build * feat(spanner): organize imports to fix vet.sh build * feat(spanner): golint changes to fix vet.sh build * feat(spanner): add support for Proto column DDL (#7292) * feat(spanner): add proto changes for Proto Columns DDL support * feat(spanner): add Proto descriptor file and integration tests for Proto DDL feature * feat(spanner): skip pg tests and code refactoring for proto ddl * feat(spanner): rename NewDatabaseAdminRESTClient to NewDatabaseAdminClient due to visibility label issue fix * feat(spanner): remove hardcoded cloud-devel host * feat(spanner): remove hardcoded project id * feat(spanner): revert autogenerated code * feat(spanner): just to validate integration tests running * feat(spanner): change copyright year * feat(spanner): set project id for integration tests * feat(spanner): use jsoniter instead of json for marshal and unmarshal * feat(spanner): revert presubmit.sh changes * chore(spanner): run integration tests in presubmit * chore(spanner): revert presubmit.sh changes * feat(spanner): fix json --------- Co-authored-by: rahul2393 <irahul@google.com>
This PR contains implementation changes to add support for handling null values in Proto Messages and Proto Enum type columns. Also the PR has changes to get
protoTypeFqnfor nil types.