Skip to content

Conversation

gatewaycat
Copy link

@gatewaycat gatewaycat commented May 13, 2025

Resolves #1020, resolves #989

✅ Readme updated
✅ New integration test added
✅ Integration tests passed

Problem

There is no functional dependency test. A column is functionally dependent on other columns in a table if each distinct combination of those others always leads to the same (possibly null) value in our column.

Example. In this table, customer_name is functionally dependent on customer_id. The important part is that both rows for customer 2 have the same name "Brock."

order_id customer_id customer_name
1001 1 Ash
1002 2 Brock
1003 2 Brock
1004 3 Ash
1005 4

Solution

Add a functional_dependency generic test. The implementation is modeled on PR #177, which introduced a different generic test.

Usage. To test customer_name is functionally dependent on customer_id.

models:
  - name: orders
    columns:
      - name: customer_name
        tests:
        - dbt_utils.functional_dependency:
            depends_on:
              - customer_id

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)

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.

Add functional_dependency test (PR included) Functional Dependency Test Macro

1 participant