Writing containers containing nested Decimal to BigQuery fails
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 4.7k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 196
Description
This piece of code: [https://github.com/apache/beam/blob/master/sdks/python/apache_beam/io/gcp/bigquery_tools.py#L946](https://github.com/apache/beam/blob/master/sdks/python/apache_beam/io/gcp/bigquery_tools.py#L946) is attempting to handle the case when inserting objects of type decimal.Decimal into BigQuery by converting them to string.
This works but doesn't handle the case when the `v` is really a container of nested objects (e.g. a dict), and one of them is a decimal.Decimal. This can easily happen when using ReadFromBigQuery on a table with nested schema.
Note how `to_json_value`, which is being called here, is recursive for this reason. I verified that a fix for my crash is to insert
```
if isinstance(obj, decimal.Decimal):
obj = str(obj)
```
in the beginning of to_json_value.
Imported from Jira [BEAM-10314](https://issues.apache.org/jira/browse/BEAM-10314). Original Jira may contain additional context.
Reported by: alexanderfaxa.
Contributor guide
Assessment
This issue has not been assessed yet.