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

Respect Snowflake Quoting

Open ludwig-solita opened this issue 1 year ago • 2 comments

Problem

Quoting isn't respected when altering Snowflake tables with non-ansi-sql compliant names. This throws an error when syncing columns in incremental models. I didn't create a new issue since this already seems to recognize the problem https://github.com/dbt-labs/dbt-adapters/issues/250

I created a new PR since I messed up the commit history with an unverified Github Account. Original PR: https://github.com/dbt-labs/dbt-snowflake/pull/923 @VersusFacit

image image image

Solution

Instead of just using column.name for the alter statements I've added the adapter.quote to properly respect the quoting configuration in yaml-files

Tests

I haven't written any tests in this project before so any help would be appreciated. The below code would essentially be the test.

Configure project.yml to use quoting for identifiers

quoting:
  identifier: true

Create the table with CTAS

{{
    config(
        materialized="incremental",
        on_schema_change='sync_all_columns'
    )
}}
SELECT 'Hello world!' as original_column

Add new columns

{{
    config(
        materialized="incremental",
        on_schema_change='sync_all_columns'
    )
}}
SELECT 'Hello world!' as original_column
,'Greetings. I come from a non-ansi compliant planet' as "NoN AnSi CoMpLiAnT CoLuMn"
,'Greetings. I come from an ansi compliant planet' as ANSI_COMPLIANT_COLUMN

Checklist

  • [x] I have read the contributing guide and understand what's expected of me

  • [x] I have run this code in development and it appears to resolve the stated issue image

  • [x] This PR includes tests, or tests are not required/relevant for this PR It's a quite minor change.

  • [x] This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX It does affect the adapter. I've had discussions with @ernestoongaro regarding the problem.

ludwig-solita avatar Mar 15 '24 16:03 ludwig-solita

@ludwig-solita is there an open dbt-snowflake issue for this? If not can you please open one? thanks! I couldn't find one on dbt-labs/dbt-core#923 either

dataders avatar Mar 21 '24 20:03 dataders

Quoting isn't respected when altering Snowflake tables with non-ansi-sql compliant names. This throws an error when syncing columns in incremental models. I didn't create a new issue since this already seems to recognize the problem

Found this one in the core repo. https://github.com/dbt-labs/dbt-adapters/issues/250

ludwig-solita avatar Mar 21 '24 20:03 ludwig-solita