Properly unmarshal JSON values into golang values when inserting table data
Closes #286 Closes #334 Closes #144 Closes #389 Closes #426
I have the same issue.
Workaround meanwhile we do
func decodePayload(payload string, v any) error {
err := decodePayloadBigquery(payload, v)
if err != nil {
return decodePayloadFromEmulator(payload, &v)
}
return nil
}
func decodePayloadBigquery(payload string, v any) error {
err := json.Unmarshal([]byte(payload), &v)
if err != nil {
return fmt.Errorf("failed to unmarshal payload from bigquery: %w", err)
}
return nil
}
func decodePayloadFromEmulator(payload string, v any) error {
payload, err := strconv.Unquote(payload)
if err != nil {
return fmt.Errorf("failed to unquote payload: %w", err)
}
err = json.Unmarshal([]byte(payload), v)
if err != nil {
return fmt.Errorf("failed to unmarshal payload from emulator: %w", err)
}
return nil
}
@goccy mind reviewing this one for @renevall? Hope you're well!
If anyone's interested in a plug-in solution, I've used this fix and rebased it with the current repo and packaged it into a docker image: https://github.com/eduhenke/bigquery-emulator/pkgs/container/bigquery-emulator. Just use ghcr.io/eduhenke/bigquery-emulator:0.6.7
Guess we're still waiting on the status of this, any updates? @goccy
This has been merged and released in the Recidiviz fork (which includes many other updates) https://github.com/Recidiviz/bigquery-emulator/releases/tag/v0.6.6-recidiviz.0