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

feat(spanner): enable row.ToStructLenient to work with STRUCT data type #5944

Merged
merged 4 commits into from
Apr 27, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
incorporate requested changes
rahul2393 committed Apr 26, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit f6328f8b0568d162e02b3d0c5eeeadfaf807d36e
18 changes: 9 additions & 9 deletions spanner/value.go
Original file line number Diff line number Diff line change
@@ -986,7 +986,7 @@ func parseNullTime(v *proto3.Value, p *NullTime, code sppb.TypeCode, isNull bool

// decodeValue decodes a protobuf Value into a pointer to a Go value, as
// specified by sppb.Type.
func decodeValue(v *proto3.Value, t *sppb.Type, ptr interface{}, opts ...DecodeOptions) error {
func decodeValue(v *proto3.Value, t *sppb.Type, ptr interface{}, opts ...decodeOptions) error {
if v == nil {
return errNilSrc()
}
@@ -1891,7 +1891,7 @@ func decodeValue(v *proto3.Value, t *sppb.Type, ptr interface{}, opts ...DecodeO
if err != nil {
return err
}
s := DecodeSetting{
s := decodeSetting{
Lenient: false,
}
for _, opt := range opts {
@@ -3049,19 +3049,19 @@ func errDecodeStructField(ty *sppb.StructType, f string, err error) error {
return se
}

// DecodeSetting contains all the settings for decoding from spanner struct
type DecodeSetting struct {
// decodeSetting contains all the settings for decoding from spanner struct
type decodeSetting struct {
Lenient bool
}

// DecodeOptions is the interface to change decode struct settings
type DecodeOptions interface {
Apply(s *DecodeSetting)
// decodeOptions is the interface to change decode struct settings
type decodeOptions interface {
Apply(s *decodeSetting)
}

type withLenient struct{ lenient bool }

func (w withLenient) Apply(s *DecodeSetting) {
func (w withLenient) Apply(s *decodeSetting) {
s.Lenient = w.lenient
}

@@ -3109,7 +3109,7 @@ func decodeStruct(ty *sppb.StructType, pb *proto3.ListValue, ptr interface{}, le
// We don't allow duplicated field name.
return errDupSpannerField(f.Name, ty)
}
opts := []DecodeOptions{withLenient{lenient: lenient}}
opts := []decodeOptions{withLenient{lenient: lenient}}
// Try to decode a single field.
if err := decodeValue(pb.Values[i], f.Type, v.FieldByIndex(sf.Index).Addr().Interface(), opts...); err != nil {
return errDecodeStructField(ty, f.Name, err)