diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cdee1b..e297377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) @@ -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) diff --git a/integration_tests/models/model_struct.sql b/integration_tests/models/model_struct.sql index 9d256b7..23fc6b8 100644 --- a/integration_tests/models/model_struct.sql +++ b/integration_tests/models/model_struct.sql @@ -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, diff --git a/integration_tests/tests/test_generate_model_struct_yaml.sql b/integration_tests/tests/test_generate_model_struct_yaml.sql index 44c1d92..fc33bf4 100644 --- a/integration_tests/tests/test_generate_model_struct_yaml.sql +++ b/integration_tests/tests/test_generate_model_struct_yaml.sql @@ -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 @@ -39,4 +66,6 @@ models: {% endset %} +{% endif %} + {{ assert_equal (actual_source_yaml | trim, expected_source_yaml | trim) }} diff --git a/macros/generate_model_yaml.sql b/macros/generate_model_yaml.sql index c36b01d..cdeab71 100644 --- a/macros/generate_model_yaml.sql +++ b/macros/generate_model_yaml.sql @@ -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('') %}