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

[Bug] Reserved words cause contract enforcement query to fail #1312

Closed
2 tasks done
PieterBos94 opened this issue Jul 31, 2024 · 2 comments
Closed
2 tasks done

[Bug] Reserved words cause contract enforcement query to fail #1312

PieterBos94 opened this issue Jul 31, 2024 · 2 comments
Labels
bug Something isn't working model_contracts

Comments

@PieterBos94
Copy link

PieterBos94 commented Jul 31, 2024

Is this a new bug in dbt-bigquery?

  • I believe this is a new bug in dbt-bigquery
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

When having columns like "group" or "following" the contract enforcement query breaks because it does not use backticks "`" around the columns.

Expected Behavior

That the reserved column names have backticks around them (`) so BigQuery doesn't give errors with reserved names while running the query that checks the contract.

Steps To Reproduce

  1. Create a model (test_following.sql):
SELECT
1 AS `following`,
"2" AS `group`
  1. Create a yaml with the following config:
models:
  - name: test_following
    config:
      materialized: table
      contract:
        enforced: true
    columns:
    - name: following
       description: ""
      data_type: int64
      data_tests:
        - unique
        - not_null
    - name: group
       data_type: string
       description: ""
  1. Build the model, this gives an BigQuery error since the query does not work

Relevant log output

This is the query that is generated that fails:

select * from (
select


cast(null as int64)
as following,

cast(null as string)
as group
) as __dbt_sbq
where false and current_timestamp() = current_timestamp()
limit 0

Environment

- OS: DBT cloud
- Python:  DBT cloud
- dbt-core: Keep on latest in DBT cloud
- dbt-bigquery: 1.9.0

Additional Context

I saw that another issue exists for nested columns: #1278
So probably good to fix both with the correct quoting added.

@PieterBos94 PieterBos94 added bug Something isn't working triage labels Jul 31, 2024
@anaghshineh
Copy link

Hey, @PieterBos94 – this seems to work fine for me when I test locally if I set quote: true for those two fields. Are you seeing different behavior? I looked at your other, related issue re: nested fields, and it does seem like that needs work to work as expected with quote: true.

@PieterBos94
Copy link
Author

Hey, @anaghshineh
I did not notice that as an option on columns and it also did not come up when talking with support, and it does indeed fix the problem. Thanks for the help!

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

No branches or pull requests

3 participants