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

[Feature] add "foreign_reference" to constraints for BigQuery #9813

Closed
3 tasks done
mkzoi opened this issue Mar 25, 2024 · 2 comments
Closed
3 tasks done

[Feature] add "foreign_reference" to constraints for BigQuery #9813

mkzoi opened this issue Mar 25, 2024 · 2 comments
Labels
enhancement New feature or request wontfix Not a bug or out of scope for dbt-core

Comments

@mkzoi
Copy link

mkzoi commented Mar 25, 2024

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

BigQuery supports a constraint foreign_reference in addition to foreign_key, which is currently not availble in dbt. The difference is, that foreign_reference is not being enforced, which can be helpful in some cases.

Describe alternatives you've considered

Well, there is the foreign_key relationship, which is enforced. This is a weaker version.

Who will this benefit?

Adding this to models is straightforward, and allows easier navigation between models.

Are you interested in contributing this feature?

sure, if you could give me some pointers to get started.

Anything else?

It seems a rather undocumented feature; see the code block in Google BigQuery DDL reference docs.

@mkzoi mkzoi added enhancement New feature or request triage labels Mar 25, 2024
@dbeatty10
Copy link
Contributor

Thanks for opening this @mkzoi !

My understanding is that neither primary keys nor foreign keys are enforced in BigQuery (but specifying both are supported by the dbt-bigquery adapter). Here's a screenshot from our docs:

image

This looks like a misunderstanding of the BigQuery docs. Take this section for example:

foreign_key :=
FOREIGN KEY (column_name[, ...]) foreign_reference

foreign_reference :=
REFERENCES primary_key_table(column_name[, ...]) NOT ENFORCED

You can think of the := as defining a variable. So anytime you see foreign_reference, you'd replace it with REFERENCES primary_key_table(column_name[, ...]) NOT ENFORCED, like this:

foreign_key :=
FOREIGN KEY (column_name[, ...]) REFERENCES primary_key_table(column_name[, ...]) NOT ENFORCED

Since this doesn't look to me like a feature within BigQuery, I'm going to close this as "not planned". But please reach out if you think I'm misunderstanding something.

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
@dbeatty10 dbeatty10 added wontfix Not a bug or out of scope for dbt-core and removed triage labels Mar 29, 2024
@mkzoi
Copy link
Author

mkzoi commented Apr 2, 2024

Hi @dbeatty10,
Thanks for clearing that up - I indeed took foreign_reference as some feature within BigQuery, not as a variable. Still lots to learn :)
Thanks for the nice reply, Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix Not a bug or out of scope for dbt-core
Projects
None yet
Development

No branches or pull requests

2 participants