goccy / bigquery-emulator

BigQuery emulator server implemented in Go
MIT License
840 stars 107 forks source link

Properly unmarshal JSON values into golang values when inserting table data #335

Open ohaibbq opened 4 months ago

ohaibbq commented 4 months ago

Closes #286 Closes #334 Closes #144

renevall commented 2 weeks ago

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
}
ohaibbq commented 2 weeks ago

@goccy mind reviewing this one for @renevall? Hope you're well!