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

feat: support quoted columns in constraint #404

Merged
merged 2 commits into from
Sep 14, 2023
Merged

Conversation

hiro-o918
Copy link
Contributor

@hiro-o918 hiro-o918 commented Sep 8, 2023

Description

Resolve a error when a model has a pre-reserved named column.
Related PR: dbt-labs/dbt-core#7537.

Note

The functional test does not check the exact sql by historical reasons.
Please check a comment on the code.

Models used to test - Optional

SQL

https://github.com/dbt-labs/dbt-core/blob/5182e3c40c9aadcafdb77e7fdcd6091ae0277444/tests/adapter/dbt/tests/adapter/constraints/fixtures.py#L256-L261

select
  'blue' as "from",
  1 as id,
  '2019-01-01' as date_day

Schema

https://github.com/dbt-labs/dbt-core/blob/5182e3c40c9aadcafdb77e7fdcd6091ae0277444/tests/adapter/dbt/tests/adapter/constraints/fixtures.py#L501-L529

version: 2
models:
  - name: my_model
    config:
      contract:
        enforced: true
      materialized: table
    constraints:
      - type: check
        # this one is the on the user
        expression: ("from" = 'blue')
        columns: [ '"from"' ]
    columns:
      - name: id
        data_type: integer
        description: hello
        constraints:
          - type: not_null
        tests:
          - unique
      - name: from  # reserved word
        quote: true
        data_type: text
        constraints:
          - type: not_null
      - name: date_day
        data_type: text

Checklist

  • You followed contributing section
  • You kept your Pull Request small and focused on a single feature or bug fix.
  • You added unit testing when necessary
  • You added functional testing when necessary

@svdimchenko
Copy link
Contributor

@hiro-o918 would you mind to add model example where you do need such requirement ?

@hiro-o918
Copy link
Contributor Author

@svdimchenko
Thank you for your reaction.
This PR aims to support a model that has a column named by a pre-reserved word like from
A related PR is dbt-labs/dbt-core#7537.

This PR is still in progress because I have not set up an environment for functional tests.

@svdimchenko
Copy link
Contributor

thanks for your contribution to keep adapter up to date with dbt-core!

@svdimchenko svdimchenko merged commit 2b65fb0 into dbt-labs:main Sep 14, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enable-functional-tests Label to trigger functional testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants