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

Alias nested sub-structs for bigquery #98

Closed
1 of 5 tasks
dbeatty10 opened this issue Dec 20, 2022 · 0 comments · Fixed by #105
Closed
1 of 5 tasks

Alias nested sub-structs for bigquery #98

dbeatty10 opened this issue Dec 20, 2022 · 0 comments · Fixed by #105
Assignees
Labels
bug Something isn't working

Comments

@dbeatty10
Copy link
Contributor

The following was originally reported and described here by @Zatte

Describe the bug

Output will be ambiguous in the case of multiple sub-structs (nested columns) with the same name.

Steps to reproduce

Use the dbt-bigquery adapter and the following files:

packages.yml

packages:
  - package: dbt-labs/codegen
    version: 0.9.0

models/model_struct.sql

select 
   struct(
      "a1" as a, 
      "b1" as b
   ) as substruct1, 
   struct(
      "a2" as a, 
      "b2" as b
   ) as substruct2

Then run the following:

dbt deps
dbt run-operation generate_model_yaml --args '{"model_names": ["model_struct"]}'

Expected results

version: 2

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

      - name: substruct1.a
        description: ""

      - name: substruct1.b
        description: ""

      - name: substruct2
        description: ""

      - name: substruct2.a
        description: ""

      - name: substruct2.b
        description: ""

Actual results

version: 2

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

      - name: a
        description: ""

      - name: b
        description: ""

      - name: substruct2
        description: ""

      - name: a
        description: ""

      - name: b
        description: ""

System information

Which database are you using dbt with?

  • postgres
  • redshift
  • bigquery
  • snowflake
  • other (specify: ____________)

The output of dbt --version:

 $ dbt --version
Core:
  - installed: 1.3.1
  - latest:    1.3.1 - Up to date!

Plugins:
  - bigquery: 1.3.0 - Up to date!

Are you interested in contributing the fix?

I'll open a PR for this. The most time-consuming part will be modifying the integration tests.

Simple fix is described here:

-     {% do model_yaml.append('      - name: ' ~ column.name | lower ) %}
+     {% do model_yaml.append('      - name: ' ~ column_name  | lower ) %}

This fix is verified to work as described in my local environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant