Skip to content

Commit

Permalink
Expected result of nested struct in BigQuery (#105)
Browse files Browse the repository at this point in the history
* Expected result of nested struct in BigQuery

* Restore the intended rendering of nested `STRUCT` fields in BigQuery

* Restore the intended rendering of nested `STRUCT` fields in BigQuery
  • Loading branch information
dbeatty10 authored Dec 21, 2022
1 parent 8c1cf59 commit 9431209
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
This macro generates a series of terminal commands (appended w) bash script which creates a new file in your dbt project based off the results of the [generate_base_model](macros/generate_base_model.sql) macro. Therefore, instead of outputting in the terminal, it will create the file for you.
- Add `include_data_types` flag to `generate_source` macro ([#76](https://github.com/dbt-labs/dbt-codegen/pull/76))

## Fixes
- Fix handling of nested `STRUCT` fields in BigQuery ([#98](https://github.com/dbt-labs/dbt-codegen/issues/98), [#105](https://github.com/dbt-labs/dbt-codegen/pull/105))

## Quality of life
- Addition of the [base_model_creation](bash_scripts/base_model_creation.sh) bash script which allows users to input multiple tables as a list and generate a terminal command that will combine **all** [create_base_models](macros/create_base_models.sql) commands. This way, you can generate base models for all your sources at once.
- Instructions for contributing ([#99](https://github.com/dbt-labs/dbt-codegen/issues/99), [#104](https://github.com/dbt-labs/dbt-codegen/pull/104))
Expand All @@ -42,7 +45,7 @@ This macro generates a series of terminal commands (appended w) bash script whic
- Add optional `name` arg to `generate_source` ([#64](https://github.com/dbt-labs/dbt-codegen/issues/64), [#66](https://github.com/dbt-labs/dbt-codegen/pull/66))

## Fixes
- `generate_model_yaml` now correctly handles nested (`STRUCT`) fields in BigQuery ([#27](https://github.com/dbt-labs/dbt-codegen/issues/27), [#54](https://github.com/dbt-labs/dbt-codegen/pull/54))
- `generate_model_yaml` now correctly handles nested `STRUCT` fields in BigQuery ([#27](https://github.com/dbt-labs/dbt-codegen/issues/27), [#54](https://github.com/dbt-labs/dbt-codegen/pull/54))

## Contributors:
- [@rahulj51](https://github.com/rahulj51) (#51)
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/models/model_struct.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% if target.type == "bigquery" %}

{#--- This exists to test the BigQuery-specific behavior reqeusted in #27 -#}
{#--- This exists to test the BigQuery-specific behavior requested in #27 -#}
select
STRUCT(
source,
Expand Down
29 changes: 29 additions & 0 deletions integration_tests/tests/test_generate_model_struct_yaml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@
)
%}

{% if target.type == "bigquery" %}

{% set expected_source_yaml %}
version: 2

models:
- name: model_struct
description: ""
columns:
- name: analytics
description: ""

- name: analytics.source
description: ""

- name: analytics.medium
description: ""

- name: analytics.source_medium
description: ""

- name: col_x
description: ""

{% endset %}

{% else %}

{% set expected_source_yaml %}
version: 2
Expand All @@ -39,4 +66,6 @@ models:

{% endset %}

{% endif %}

{{ assert_equal (actual_source_yaml | trim, expected_source_yaml | trim) }}
2 changes: 1 addition & 1 deletion macros/generate_model_yaml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% set column_name = column.name %}
{% endif %}

{% do model_yaml.append(' - name: ' ~ column.name | lower ) %}
{% do model_yaml.append(' - name: ' ~ column_name | lower ) %}
{% do model_yaml.append(' description: "' ~ column_desc_dict.get(column.name | lower,'') ~ '"') %}
{% do model_yaml.append('') %}

Expand Down

0 comments on commit 9431209

Please sign in to comment.