Add custom classes to represent Google Well Known Types#1271
Add custom classes to represent Google Well Known Types#1271hectorcast-db merged 9 commits intomainfrom
Conversation
We specifically cannot use Proto FieldMask because it encapsulates the descriptor of the message, and validates the content. Except for that one, we could use the others. But this way we are slightly more consistent. |
I think we can use protoLibrary for marshalling/unmarshalling the fieldMask. However, we can't use the standard function to create it, as it needs a proto message. Instead, we can manually set the Paths field in the fieldMask message. |
Mmm... We can do that with the others. Like, Thoughts? |
Looks good, but why are we storing this as time.Time and not timepb.Time? |
We are exposing this to the customer. I guess is a matter of preference on what we want the user to see: In python we did our own classes which "mimic" the python native time. So exposing native time, while not the same, seems slightly more consistent and requires less rework. Right now: We can change it again, but python this was already done, reviews, tested and ready to go. |
dd1be67 to
ebcdc9a
Compare
7e6b79e to
6cd5094
Compare
| // field mask from a string according to Google Well Known Type | ||
| func (f *FieldMask) UnmarshalJSON(data []byte) error { | ||
| if f == nil { | ||
| return fmt.Errorf("json.Unmarshal on nil pointer") |
There was a problem hiding this comment.
| return fmt.Errorf("json.Unmarshal on nil pointer") | |
| return fmt.Errorf("FieldMask.UnmarshalJSON on nil pointer") |
| // | ||
| // Example: | ||
| // | ||
| // customDur := durationpb.New(30 * time.Second) |
There was a problem hiding this comment.
| // customDur := durationpb.New(30 * time.Second) | |
| // customDur := duration.New(30 * time.Second) |
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Discussed with the team and already applied the relevant changes.
## Changes Implements conversion support for SDK native types across the dyn package conversion layer (FromTyped, ToTyped, Normalize). Supports three SDK types that use custom JSON marshaling: - duration.Duration: Protobuf duration format (e.g., "300s") - time.Time: RFC3339 timestamp format (e.g., "2023-12-25T10:30:00Z") - fieldmask.FieldMask: Comma-separated paths (e.g., "name,age,email") The implementation uses a generic approach with all SDK-specific code in sdk_native_types.go and sdk_native_types_test.go. ## Why The new Postgres APIs use these types and need the to/from conversion to work. Also see databricks/databricks-sdk-go#1271. --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
What changes are proposed in this pull request?
Add custom classes to represent Google Well Known Types
These classes have custom serialization:
https://protobuf.dev/reference/protobuf/google.protobuf/
How is this tested?
Added unit tests.
NO_CHANGELOG=true