apache / apache/beam

Writing containers containing nested Decimal to BigQuery fails

Open
#20,439 0 comments 0 reactions 0 assignees View on GitHub
bug gcp io P3 python
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.