Skip to content

Commit

Permalink
structs
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Feb 6, 2024
1 parent f486f73 commit 1f2a06b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dbt/include/bigquery/macros/utils/safe_cast.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
(select array_agg(safe_cast(i as {{type.lower()[6:-1]}})) from unnest({{field}}) i)
{%- elif type.lower() == 'json' and field is mapping -%}
safe_cast(json {{ dbt.string_literal(tojson(field)) }} as json)
{%- elif type.lower().startswith('struct') and field is string -%}
safe_cast({{field.strip('"').strip("'")}} as {{type}})
{%- else -%}
safe_cast({{field}} as {{type}})
{%- endif -%}
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/adapter/unit_testing/test_unit_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def data_types(self):
"""{"name": "Cooper", "forname": "Alice"}""",
],
["""json '{"name": "Cooper", "forname": "Alice"}'""", "{}"],
# structs
["STRUCT('Isha' as name, 22 as age)", """'STRUCT("Isha" as name, 22 as age)'"""],
[
"STRUCT('Kipketer' AS name, [23.2, 26.1, 27.3, 29.4] AS laps)",
"""'STRUCT("Kipketer" AS name, [23.2, 26.1, 27.3, 29.4] AS laps)'""",
],
]


Expand Down

0 comments on commit 1f2a06b

Please sign in to comment.