From 5719a24637b081d82d95915d4ba161cce2a1a8ba Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Tue, 21 Apr 2020 14:21:52 -0400 Subject: [PATCH] (#2336) Fix for non-json-serializable values in BigQuery nested columns --- core/dbt/clients/agate_helper.py | 3 ++- .../test_bigquery_repeated_records.py | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/dbt/clients/agate_helper.py b/core/dbt/clients/agate_helper.py index 9e26dc88a71..29f285edac3 100644 --- a/core/dbt/clients/agate_helper.py +++ b/core/dbt/clients/agate_helper.py @@ -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 @@ -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) diff --git a/test/integration/022_bigquery_test/test_bigquery_repeated_records.py b/test/integration/022_bigquery_test/test_bigquery_repeated_records.py index 17c529291b0..06b22fceec0 100644 --- a/test/integration/022_bigquery_test/test_bigquery_repeated_records.py +++ b/test/integration/022_bigquery_test/test_bigquery_repeated_records.py @@ -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 @@ -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 """ @@ -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}]' ] }