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

[bigquery] Add scaffolding for the Storage Write API #720

Merged
merged 8 commits into from
Jun 13, 2024
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
15 changes: 10 additions & 5 deletions clients/bigquery/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,21 @@ func castColVal(colVal any, colKind columns.Column, additionalDateFmts []string)
// MongoDB will return the native objects back such as `map[string]any{"hello": "world"}`
// Relational will return a string representation of the struct such as `{"hello": "world"}`
func EncodeStructToJSONString(value any) (string, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need this for the Storage Write API.

if colValString, isOk := value.(string); isOk {
if strings.Contains(colValString, constants.ToastUnavailableValuePlaceholder) {
if stringValue, isOk := value.(string); isOk {
if strings.Contains(stringValue, constants.ToastUnavailableValuePlaceholder) {
return fmt.Sprintf(`{"key":"%s"}`, constants.ToastUnavailableValuePlaceholder), nil
}
return colValString, nil
return stringValue, nil
}

colValBytes, err := json.Marshal(value)
bytes, err := json.Marshal(value)
if err != nil {
return "", fmt.Errorf("failed to marshal colVal: %w", err)
}
return string(colValBytes), nil

stringValue := string(bytes)
if strings.Contains(stringValue, constants.ToastUnavailableValuePlaceholder) {
slog.Error("encoded JSON value contains the toast unavailable value placeholder")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return this too

return fmt.Sprintf(`{"key":"%s"}`, constants.ToastUnavailableValuePlaceholder), nil

}
return stringValue, nil
}