Skip to content

Add allow_nulls option to comparison checks - #1492

Merged
mwojtyczka merged 4 commits into
databrickslabs:mainfrom
alvaromoureupm:feat/allow-nulls-comparison-checks
Sep 2, 2026
Merged

Add allow_nulls option to comparison checks#1492
mwojtyczka merged 4 commits into
databrickslabs:mainfrom
alvaromoureupm:feat/allow-nulls-comparison-checks

Conversation

@alvaromoureupm

Copy link
Copy Markdown
Contributor

Changes

Adds an allow_nulls argument (default True) to the six comparison row-level checks — is_equal_to, is_not_equal_to, is_not_less_than, is_not_greater_than, is_in_range, is_not_in_range — implementing the approach suggested by @ghanse in the linked issue.

Because of Spark's null-comparison semantics, null values always pass these checks today; making nulls fail requires pairing each rule with a separate is_not_null rule, which splits the failure metadata across two checks. With allow_nulls=False:

  • null values fail the check with a dedicated message (Column 'x' value is null), while non-null failures keep their existing messages
  • the auto-generated condition alias gains an is_null_or_ prefix (e.g. x_is_null_or_not_equal_to_value), mirroring the existing is_not_null_and_is_in_list naming convention

The default behavior is fully backwards compatible: with allow_nulls=True (default) conditions, messages, and aliases are unchanged. The logic is shared via a single _make_condition_handling_nulls helper.

If this direction looks good, I'm happy to follow up extending allow_nulls to other null-passing checks (e.g. list membership checks) in a separate PR.

Linked issues

Resolves #1395

Tests

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

Ran locally: make fmt, make lint (mypy + pylint 10.00/10), full tests/unit/test_row_checks.py + tests/unit/test_check_func_signatures.py (178 passed), and the new integration test test_col_comparison_checks_with_nulls_failing against a Databricks serverless workspace (passed).

Documentation and Demos

  • added/updated demos
  • added/updated docs
  • added/updated agent skills

@alvaromoureupm
alvaromoureupm requested a review from a team as a code owner August 31, 2026 21:11
@alvaromoureupm
alvaromoureupm requested review from mwojtyczka and removed request for a team August 31, 2026 21:11
@CLAassistant

CLAassistant commented Aug 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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

@alvaromoureupm
alvaromoureupm force-pushed the feat/allow-nulls-comparison-checks branch 2 times, most recently from 156d1f7 to beeb657 Compare August 31, 2026 21:19
Comparison checks (is_equal_to, is_not_equal_to, is_not_less_than,
is_not_greater_than, is_in_range, is_not_in_range) follow Spark's
null-comparison semantics, so null values always pass them. Combining
them with a separate is_not_null rule splits the failure metadata
across two checks.

Add an allow_nulls argument (default True, fully backwards compatible)
so null values can fail these checks directly. When allow_nulls=False,
the condition also fails on nulls with a dedicated message and an
_is_null_or_-prefixed alias, mirroring is_not_null_and_is_in_list.

Resolves databrickslabs#1395

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alvaromoureupm
alvaromoureupm force-pushed the feat/allow-nulls-comparison-checks branch from beeb657 to 17d359d Compare August 31, 2026 21:20
Comment thread docs/dqx/docs/reference/quality_checks.mdx
Comment thread src/databricks/labs/dqx/check_funcs.py
Comment thread tests/integration/test_row_checks.py

@mwojtyczka mwojtyczka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - yes we can apply the same logic to other checks

Comment thread tests/integration/test_row_checks.py
@mwojtyczka mwojtyczka added the Approved to Merge When PR is reviewed and approved. To be merged once all tests pass label Sep 1, 2026
…checks

Add test_col_comparison_checks_with_nulls_failing_column_expression, which
exercises the allow_nulls=False path with a column expression (a + b). It
verifies that nullness is reported against the whole expression when any
operand is null, and that non-null out-of-bounds values still fail with the
expression rendered in the message.

Co-authored-by: Isaac <no-reply@databricks.com>
is_in_range gained an allow_nulls parameter, so build_profiling_rule now
enumerates it as a non-column parameter. Unsupplied by the profiler, it
freezes to None (its unset default), matching the built-in seeder shape.
Update the stale expectation in test_freezes_non_column_parameter_values.

Co-authored-by: Isaac <no-reply@databricks.com>
@mwojtyczka
mwojtyczka merged commit caaa997 into databrickslabs:main Sep 2, 2026
54 of 55 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]: additional is_not_null_and_* checks

3 participants