Skip to content

Feature/validate upstream tables#1309

Open
STEFANOVIVAS wants to merge 8 commits into
databrickslabs:mainfrom
STEFANOVIVAS:feature/validate_upstream_tables
Open

Feature/validate upstream tables#1309
STEFANOVIVAS wants to merge 8 commits into
databrickslabs:mainfrom
STEFANOVIVAS:feature/validate_upstream_tables

Conversation

@STEFANOVIVAS

@STEFANOVIVAS STEFANOVIVAS commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Changes

validate_upstream_table added to check_funcs.py — a new dataset-level check that compares an aggregate metric (row count by default, or any curated/built-in aggregate) computed on the checked DataFrame against the same aggregate computed on a reference (upstream) table or DataFrame, with optional abs_tolerance/rel_tolerance and independent row_filter/ref_row_filter on each side.

Linked issues

Resolves #1046

Tests

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

Documentation and Demos

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

@STEFANOVIVAS
STEFANOVIVAS requested a review from a team as a code owner July 7, 2026 02:52
@STEFANOVIVAS
STEFANOVIVAS requested review from pratikk-databricks and removed request for a team July 7, 2026 02:52
@CLAassistant

CLAassistant commented Jul 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI 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.

Pull request overview

This PR introduces a new dataset-level quality check, validate_upstream_table, to validate ingestion correctness by comparing an aggregate metric (row count by default, or other curated/built-in aggregates) computed on the checked DataFrame against the same metric computed on an upstream reference (DataFrame via ref_df_name or Unity Catalog table via ref_table), with optional absolute/relative tolerances and independent row filters.

Changes:

  • Added validate_upstream_table to check_funcs.py, including parameter validation, aggregate evaluation on both sides, and tolerance/null-safe comparison logic.
  • Added unit and integration tests covering parameter validation, tolerance behavior, row filtering, '*'/count(*) usage, and ref-table vs ref-DataFrame paths.
  • Documented the new check in the quality checks reference, including YAML and Python usage examples.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/databricks/labs/dqx/check_funcs.py Adds the new dataset-level upstream aggregate comparison check implementation.
tests/unit/test_dataset_checks.py Adds rule-build-time parameter validation tests for the new check.
tests/integration/test_dataset_checks.py Adds end-to-end Spark integration tests for the new check’s runtime behavior.
docs/dqx/docs/reference/quality_checks.mdx Documents the new check and adds usage examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/databricks/labs/dqx/check_funcs.py Outdated

@ghanse ghanse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Headed in the right direction. Left some comments. Do you also want to add a similar check for a custom SQL query?

Comment thread src/databricks/labs/dqx/check_funcs.py Outdated


@register_rule("dataset")
def validate_upstream_table(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think a naming convention like "matches_upstream_table" might be clearer. For example aggr_matches_upstream_table for this check.

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.

Maybe keep it even more generic: aggr_matches_upstream_dataset since it can be a table or a dataframe

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In fact there isn’t even an obligation to be an upstream table, right? It’s just as just a validation between tables/dataframes.

@mwojtyczka mwojtyczka Jul 16, 2026

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.

@STEFANOVIVAS Correct, can you pls rename it to aggr_matches_dataset? this will also require update to docs and docstrings. We can have upstream table validation as one of the examples where this could be used.

Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
@ghanse ghanse added under-review This PR is currently being reviewed by one of DQX maintainers. needs-changes Changes required after review labels Jul 7, 2026
Comment thread docs/dqx/docs/reference/quality_checks.mdx Outdated

@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.

Review of validate_upstream_table. Useful check and largely correct; main themes are: it reimplements existing aggregate machinery (_is_aggr_compare + _get_ref_df) rather than composing it, and a few edges around filter validation, the empty-upstream message, and the exact-equality default. Inline below.

Cleared: rel_tolerance has no div-by-zero (guarded by max()); the apply closure captures spark/ref_dfs correctly (standard dataset-check pattern); .limit(1) matches _is_aggr_compare; behavioral coverage lives in the integration tests (dataset checks can't be unit-tested without Spark).

Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/check_funcs.py Outdated
Comment thread src/databricks/labs/dqx/check_funcs.py Outdated

@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.

Going in the right direction, left some comments

@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. Just one request to rename the function to aggr_matches_dataset to make it more generic and update docs and docs strings accordingly

@STEFANOVIVAS

Copy link
Copy Markdown
Contributor Author

LGTM. Just one request to rename the function to aggr_matches_dataset to make it more generic and update docs and docs strings accordingly

Hi, @mwojtyczka! One thing to point out: Should we implement a group by clause in this check? _is_aggr_compare function already let us apply it in the input Dataframe. Could make sense because in many situations we need to make a per-group reconciliation (date, region,source_system,etc).

@mwojtyczka

Copy link
Copy Markdown
Contributor

LGTM. Just one request to rename the function to aggr_matches_dataset to make it more generic and update docs and docs strings accordingly

Hi, @mwojtyczka! One thing to point out: Should we implement a group by clause in this check? _is_aggr_compare function already let us apply it in the input Dataframe. Could make sense because in many situations we need to make a per-group reconciliation (date, region,source_system,etc).

yes makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-changes Changes required after review under-review This PR is currently being reviewed by one of DQX maintainers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Validation of upstream tables

5 participants