Skip to content

Feature: Foreign key check with null safe support#1106

Merged
mwojtyczka merged 23 commits intodatabrickslabs:mainfrom
IvannKurchenko:feature/foreign-key-check-with-null-safe-support
Apr 24, 2026
Merged

Feature: Foreign key check with null safe support#1106
mwojtyczka merged 23 commits intodatabrickslabs:mainfrom
IvannKurchenko:feature/foreign-key-check-with-null-safe-support

Conversation

@IvannKurchenko
Copy link
Copy Markdown
Contributor

@IvannKurchenko IvannKurchenko commented Apr 7, 2026

Changes

Added null_safe parameter to foreign_key check to explicitly enable null foreign key comparison. To distinguish cases when null foreign key is matched vs foreign key is not found completely when null_safe=True wrapping even single columns comparison into Struct.

Special behaviour

Enabling null_safe=True on a previously non-null-safe single-column FK changes the message and auto created check name:

  • the rule name from a_not_exists_in_ref_bstruct_a_as_a_not_exists_in_ref_struct_b_as_a
  • the violation message from Value '...' in column 'a' not found in reference column 'b''struct(a AS a)' ... 'struct(b AS a)'

Linked issues

#1069

Resolves #1069

Tests

  • manually tested
  • added unit tests
  • added integration tests
  • added end-to-end tests
  • added performance tests

@IvannKurchenko IvannKurchenko marked this pull request as ready for review April 8, 2026 15:58
@IvannKurchenko IvannKurchenko requested a review from a team as a code owner April 8, 2026 15:58
@IvannKurchenko IvannKurchenko requested review from nehamilak-db and removed request for a team April 8, 2026 15:58
@github-actions
Copy link
Copy Markdown
Contributor

All commits in PR should be signed ('git commit -S ...'). See https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

@mwojtyczka
Copy link
Copy Markdown
Contributor

@IvannKurchenko thank you for the PR. We require all commits to be signed. Please follow the instructions: https://databrickslabs.github.io/dqx/docs/dev/contributing/#first-contribution

Copy link
Copy Markdown
Contributor

@mwojtyczka mwojtyczka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution — the idea of wrapping single columns in a struct to preserve NULL-aware base_condition is a sound approach. However, the join condition inside the apply closure is not updated for null-safe matching, which means the null-safe tests should fail. See inline comments for details.

Summary:

Severity Item
Blocker Join condition uses == which cannot match NULL struct fields — null-safe matching won't work
High Missing validation for negate + null_safe despite being documented as raising an error
Low Docstring grammar

Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/check_funcs.py
Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
@mwojtyczka mwojtyczka added under-review This PR is currently being reviewed by one of DQX maintainers. needs-changes Changes required after review and removed under-review This PR is currently being reviewed by one of DQX maintainers. labels Apr 15, 2026
@mwojtyczka
Copy link
Copy Markdown
Contributor

@IvannKurchenko you need to repush all commits, the first commit is still not signed

@mwojtyczka mwojtyczka marked this pull request as draft April 21, 2026 11:32
@IvannKurchenko IvannKurchenko force-pushed the feature/foreign-key-check-with-null-safe-support branch 4 times, most recently from 68653ea to fbbd548 Compare April 22, 2026 05:17
@IvannKurchenko IvannKurchenko force-pushed the feature/foreign-key-check-with-null-safe-support branch from fbbd548 to 7b2b51c Compare April 22, 2026 05:21
@IvannKurchenko
Copy link
Copy Markdown
Contributor Author

@mwojtyczka Thank you for the review and feedback. I have added the tests you requested, along with a case for negate enabled.

Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/check_funcs.py
Comment thread src/databricks/labs/dqx/check_funcs.py
Copy link
Copy Markdown
Contributor

@mwojtyczka mwojtyczka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mwojtyczka mwojtyczka added Approved to Merge When PR is reviewed and approved. To be merged once all tests pass and removed under-review This PR is currently being reviewed by one of DQX maintainers. labels Apr 23, 2026
@mwojtyczka
Copy link
Copy Markdown
Contributor

mwojtyczka commented Apr 23, 2026

@mwojtyczka I apologise for this, there was also merge commits from GitHub, now everything is singed.

No worries, thanks for your awesome contribution! will merge as soon as all tests pass

@mwojtyczka mwojtyczka merged commit 279c441 into databrickslabs:main Apr 24, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved to Merge When PR is reviewed and approved. To be merged once all tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Foreign key check with null safe support

2 participants