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

Add new functional_dependency generic test macro #988

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edejong-dbc
Copy link

@edejong-dbc edejong-dbc commented Feb 20, 2025

resolves #989

Problem

Currently, dbt-utils does not provide a built-in test to ensure that a set of columns (the “determinants”) functionally determines a single “dependent” column. This can be important for validating data integrity, for example, to confirm that every (order_id, product_id) maps to exactly one quantity.

Solution

Adds a new functional_dependency test under macros/generic_tests/.

This test checks that there is exactly one distinct dependent value for each unique combination of determinant columns.

Optionally allows filtering records via a where clause.

Includes example seed CSVs showing both passing and failing scenarios (test_functional_dependency_pass.csv and test_functional_dependency_fail.csv).

Adds a sample schema.yml demonstrating usage with data_tests, how to specify multiple determinant columns, and how to apply a custom where condition.

Provides documentation for the new test following dbt-utils conventions, describing arguments, usage patterns, and an example snippet similar to the style used in other generic tests.

Checklist

  • This code is associated with an issue which has been triaged and accepted for development.
  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the README.md (if applicable)

* Provide passing/failing seed CSVs (`data_test_functional_dependency_pass.csv` and `data_test_functional_dependency_fail.csv`)
* Add example `schema.yml` usage demonstrating `data_tests` with multiple determinants and an optional `where` clause
* Write documentation block for `functional_dependency`.
* Upgrade postgres in Docker to 13.19 to be able to run the tests on ARM architectures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Functional Dependency Test Macro
1 participant