-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Updated generate_model_yaml macro to correctly handle nested bigquery… #54
Updated generate_model_yaml macro to correctly handle nested bigquery… #54
Conversation
Hi @bodschut, thanks for opening this - as you noted in #27, we'll definitely want some integration tests to ensure everything's working correctly. Have a look at https://github.com/dbt-labs/dbt-codegen/tree/main/integration_tests/tests for some examples - you can create another source table following this pattern - you'll need to only run it if the current adapter is BigQuery of course (see |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bodschut thanks for submitting this! 🏆
I added some tests and everything looks good ✅
{% set column_name = column.name %} | ||
{% endif %} | ||
|
||
{% do model_yaml.append(' - name: ' ~ column.name | lower ) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for poking an old PR but shouldn't this line read(?):
{% do model_yaml.append(' - name: ' ~ column_name | lower ) %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure one way or the other @Zatte
@bodschut Some questions:
- What do you think of @Zatte 's question about
column_name
versuscolumn.name
? - Is there something more descriptive than
column_name
that would be accurate, likealiased_parent_column_name
? - Is
parent_column_name
even used as a parameter? It's not explicitly set here, and thegenerate_column_yaml
looks like a "private" macro internal tocodegen
rather than a "public" macro intended to be used by consumers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context; I use generate_model_yaml-source (which calls this private macro) on a nested struct in BigQuery
With the current state i only get "tail columns" as the column names (not the full parent hierarchy, dot delimited). I would expect the column names to contain the full parent hierarchy.
Example.
SQL
SELECT
struct(
"a" as a,
"b" as b
) as substruct
Current output
models:
- name: model_struct
description: ""
columns:
- name: a
description: ""
- name: b
description: ""
Expected output (with column_name
change)
models:
- name: model_struct
description: ""
columns:
- name: substruct.a
description: ""
- name: substruct.b
description: ""
The current output will be ambiguous in the case of multiple sub-structs (nested columns) with the same name like this.
SELECT
struct(
"a1" as a,
"b1" as b
) as substruct1,
struct(
"a2" as a,
"b2" as b
) as substruct2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This info is perfect @Zatte !
I was able to reproduce and see that your suggested fix works.
Opened this issue and will follow-up with a PR:
#98
I took a peek at the commit history on this -- looks like @bodschut had it correct the first time around, and I accidentally foobar'd it when resolving a merge conflict 😬
#54) * Updated generate_model_yaml macro to correctly handle nested bigquery fields * Updated changelog.md * Update macros/generate_model_yaml.sql * Integration tests Co-authored-by: Bob De Schutter <bob.deschutter@digitalswat.be> Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Co-authored-by: Doug Beatty <doug.beatty@dbtlabs.com>
This is a:
main
dev/
branchdev/
branchDescription & motivation
Fixes #27
Checklist