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

Expected result of nested struct in BigQuery #105

Merged
merged 3 commits into from
Dec 21, 2022
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
- Addition of the [create_base_models](macros/create_base_models.sql)
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.

## 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 @@ -40,7 +43,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