dbt-codegen icon indicating copy to clipboard operation
dbt-codegen copied to clipboard

Arguments for case-sensitive / quoted identifiers in `generate_model_yaml`

Open RBABI-Team opened this issue 1 year ago • 4 comments

Describe the feature

Adapter: dbt-Snowflake v1.7.4 dbt-codegen Version: 0.12.1

We have a number of legacy models in dbt that are leveraging quoted identifiers to preserve casing for downstream use cases, however dbt-codegen does not appear to preserve the case sensitivity when running the generate_model_yaml output.

Example:

models/marts/order_data.sql:

select
      "OrderID",
      "OrderDate",
      "OrderQuantity"
from {{ ref('upstream_order_data') }}

However, when I compile the following script:

{{ codegen.generate_model_yaml(
    model_names=['order_data']
) }}

It compiles to:

version: 2

models:
  - name: order_data
    description: ""
    columns:
      - name: orderid
        data_type: number
        description: ""
      - name: orderdate
        data_type: date
        description: ""
      - name: orderquantity
        data_type: number
        description: ""

Which does not allow dbt documentation/explorer to recognize the field names in the table. It would be great if we had something like the following:

{{ codegen.generate_model_yaml(
    model_names=['order_data'],
   quote_identifiers=true
) }}

Which would preserve the case of the field names and result in something like:

version: 2

models:
  - name: order_data
    description: ""
    columns:
      - name: OrderID
        quote: true
        data_type: number
        description: ""
      - name: OrderDate
        quote: true
        data_type: date
        description: ""
      - name: OrderQuantity
        quote: true
        data_type: number
        description: ""

Changing the project.yml quoting configurations appears to have no effect on this behavior.

Describe alternatives you've considered

Our hope is to eventually stop utilizing quoted identifiers all together, but we need to clean up some downstream dependencies first. For now we've been using the macro as a starting point and manually update as needed.

Additional context

This is obviously very likely Snowflake-specific, but occurs globally in our environment

Who will this benefit?

Any Snowflake users that are currently leveraging quoted identifiers downstream.

Are you interested in contributing this feature?

We'd love to help in any way we can, but could use some guidance on what an ideal solution would be

RBABI-Team avatar May 17 '24 14:05 RBABI-Team

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

github-actions[bot] avatar Nov 14 '24 02:11 github-actions[bot]

@dbeatty10

I am also facing a similar issue when dealing with a Snowflake table that has columns with Japanese names. As the RBABI-Team mentioned, having a quote_identifiers parameter would be greatly helpful.

Is this issue currently being addressed? If not, could I take care of it?

tanakou0226 avatar Nov 28 '24 11:11 tanakou0226

a similar problem seems to be solved in generate_source https://github.com/dbt-labs/dbt-codegen/pull/168

https://github.com/dbt-labs/dbt-codegen/pull/168/commits/3bc91c020c82d5085e38c46d0f19086891ad7d14#diff-ac1f19cc6a49270212a49d1fa9dd7a6be70d33681afc2d5d529f9419ded2303e

lcorneliussen avatar Apr 14 '25 13:04 lcorneliussen

Adding my vote for this issue as well. This was noticed today using the dbt-snowflake adapter.

For us, the primary issue is that the case sensitivity for table names should be preserved. However, the current functionality will convert table names to lowercase.

AdamAtValtech avatar Jun 18 '25 11:06 AdamAtValtech