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

Fix for non-json-serializable values in BigQuery nested columns #2348

Merged
merged 2 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Fix skipped node count in stdout at the end of a run ([#2095](https://github.com/fishtown-analytics/dbt/issues/2095), [#2310](https://github.com/fishtown-analytics/dbt/pull/2310))
- Fix an issue where BigQuery incorrectly used a relation's quote policy as the basis for the information schema's include policy, instead of the relation's include policy. ([#2188](https://github.com/fishtown-analytics/dbt/issues/2188), [#2325](https://github.com/fishtown-analytics/dbt/pull/2325))
- Fix "dbt deps" command so it respects the "--project-dir" arg if specified. ([#2338](https://github.com/fishtown-analytics/dbt/issues/2338), [#2339](https://github.com/fishtown-analytics/dbt/issues/2339))
- Fix "Object of type Decimal is not JSON serializable" error when BigQuery queries returned numeric types in nested data structures ([#2336](https://github.com/fishtown-analytics/dbt/issues/2336), [#2348](https://github.com/fishtown-analytics/dbt/pull/2348))

### Under the hood
- Added more tests for source inheritance ([#2264](https://github.com/fishtown-analytics/dbt/issues/2264), [#2291](https://github.com/fishtown-analytics/dbt/pull/2291))
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/clients/agate_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
import isodate
import json
import dbt.utils
from typing import Iterable, List, Dict, Union, Optional, Any

from dbt.exceptions import RuntimeException
Expand Down Expand Up @@ -92,7 +93,7 @@ def table_from_data_flat(data, column_names: Iterable[str]) -> agate.Table:
row = []
for value in list(_row.values()):
if isinstance(value, (dict, list, tuple)):
row.append(json.dumps(value))
row.append(json.dumps(value, cls=dbt.utils.JSONEncoder))
else:
row.append(value)
rows.append(row)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test__bigquery_fetch_nested_records(self):
cast('Stonebreaker' as string) as lname
) as user,
[
struct(1 as val_1, 2 as val_2),
struct(3 as val_1, 4 as val_2)
struct(1 as val_1, cast(2.12 as numeric) as val_2),
struct(3 as val_1, cast(4.83 as numeric) as val_2)
] as val

union all
Expand All @@ -38,8 +38,8 @@ def test__bigquery_fetch_nested_records(self):
cast('Brickmaker' as string) as lname
) as user,
[
struct(7 as val_1, 8 as val_2),
struct(9 as val_1, 0 as val_2)
struct(7 as val_1, cast(8 as numeric) as val_2),
struct(9 as val_1, cast(null as numeric) as val_2)
] as val
"""

Expand All @@ -54,8 +54,8 @@ def test__bigquery_fetch_nested_records(self):
'{"fname": "Johnny", "lname": "Brickmaker"}'
],
"val": [
'[{"val_1": 1, "val_2": 2}, {"val_1": 3, "val_2": 4}]',
'[{"val_1": 7, "val_2": 8}, {"val_1": 9, "val_2": 0}]'
'[{"val_1": 1, "val_2": 2.12}, {"val_1": 3, "val_2": 4.83}]',
'[{"val_1": 7, "val_2": 8}, {"val_1": 9, "val_2": null}]'
]
}

Expand Down