Skip to content

Extend summary metrics with per-check-name breakdowns#1097

Merged
mwojtyczka merged 29 commits into
mainfrom
ghanse/issue-943-extend-summary-metrics-check-name
Apr 21, 2026
Merged

Extend summary metrics with per-check-name breakdowns#1097
mwojtyczka merged 29 commits into
mainfrom
ghanse/issue-943-extend-summary-metrics-check-name

Conversation

@ghanse

@ghanse ghanse commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

Changes

Extended DQMetricsObserver to emit a new check_metrics row alongside the existing aggregates (input_row_count, error_row_count, warning_row_count, valid_row_count). The value is a JSON array of structs — one entry per check — that fits the existing metric_name / metric_value schema without widening it:

  [{"check_name": "id_is_not_null", "error_count": 1, "warning_count": 0}, ...]

Backward compatible: existing metrics unchanged, new row is additive and opt-in.

Key design decisions:

  • Backward compatible: Existing aggregate metrics are unchanged; per-check metrics are appended after them.
  • Automatically enabled: no knobs, auto-enabled.
  • Safe aliases: Check names with special characters are sanitized for use as Spark SQL aliases.
  • No new dependencies: Uses existing Spark SQL exists() higher-order function.

Linked issues

Closes #943

Tests

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

This pull request was AI-assisted by Isaac.

ghanse added 2 commits March 27, 2026 12:19
Add per-check error and warning counts to the DQMetricsObserver, allowing
users to drill down summary metrics by individual quality check name.
The engine passes check names to the observer before collecting metrics,
and the observer generates SQL expressions using exists() to count rows
matching each check.

Closes #943

Co-authored-by: Isaac
Cover per-check metric generation, custom column names, special character
sanitization, and replacement of previously set check names.

Co-authored-by: Isaac
@ghanse ghanse requested a review from a team as a code owner March 27, 2026 16:20
@ghanse ghanse requested review from grusin-db and removed request for a team March 27, 2026 16:20
@ghanse ghanse added the needs-review Ready for re-review label Mar 27, 2026

@ghanse ghanse left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good implementation. The per-check metric generation is clean, backward-compatible, and well-tested. Two minor findings below — neither is blocking but both are worth addressing.

Comment thread src/databricks/labs/dqx/metrics_observer.py Outdated
Comment thread src/databricks/labs/dqx/metrics_observer.py Outdated
@ghanse ghanse added needs-cleanup Review passed, minor cleanup before merge needs-changes Changes required after review and removed needs-review Ready for re-review needs-cleanup Review passed, minor cleanup before merge labels Mar 27, 2026
@ghanse ghanse added the needs-review Ready for re-review label Mar 29, 2026

@ghanse ghanse left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed duplicate alias collision — _build_per_check_metrics now detects when two check names sanitize to the same alias and raises DQXError. Added unit test for the edge case (e.g. check-1 vs check.1). Ready for cleanup pass.

@ghanse ghanse added needs-cleanup Review passed, minor cleanup before merge and removed needs-review Ready for re-review labels Mar 29, 2026
- Rename `default_metrics` to `all_metrics` in metrics property since
  it accumulates default, per-check, and custom metrics
- Fix copy-paste docstring in test_dq_observer_custom_column_names
  that incorrectly said "default column names"

Co-authored-by: Isaac
@ghanse

ghanse commented Mar 29, 2026

Copy link
Copy Markdown
Collaborator Author

Cleanup pass complete.

  • Renamed default_metrics to all_metrics in metrics property since it accumulates default, per-check, and custom metrics
  • Fixed copy-paste docstring in test_dq_observer_custom_column_names that incorrectly said "default column names"

Tests pass (16/16). Ready for review.

@ghanse ghanse added needs-review Ready for re-review and removed needs-cleanup Review passed, minor cleanup before merge labels Mar 29, 2026

@ghanse ghanse left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Post-cleanup final review: APPROVED

Reviewed the full diff across metrics_observer.py, engine.py, test_observer.py, and test_summary_metrics.py.

Correctness: The Spark SQL exists() higher-order function is the right approach for checking array-of-struct columns. Single-quote escaping, alias sanitization, and duplicate collision detection are all correctly implemented. The @cached_property to @property change on metrics is necessary and correct since check names are set dynamically.

Completeness: Fully addresses #943 with per-check-name error/warning counts. The track_extended_metrics flag defaults to False for full backward compatibility. Both apply_checks and apply_checks_by_metadata paths are covered since the latter delegates to the former.

Test coverage: 10 new unit tests and 2 parametrized integration tests (4 total runs) cover: default behavior, per-check metrics, metric ordering, custom column names, special character sanitization, check name replacement, empty alias error, and duplicate alias collision.

Code quality: Clean naming, proper docstrings, no dead code, pure helper function for sanitization. AGENTS.md compliant — type hints on all signatures, DQXError for exceptions, no new Any usage.

No changes required. Ready for human approval.

@ghanse ghanse added needs-approval Reviewed, and awaiting maintainer approval and removed needs-review Ready for re-review labels Mar 29, 2026
@ghanse ghanse removed the needs-changes Changes required after review label Mar 29, 2026
Comment thread src/databricks/labs/dqx/metrics_observer.py Outdated
@mwojtyczka mwojtyczka added the under-review This PR is currently being reviewed by one of DQX maintainers. label Mar 30, 2026

@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: Extend summary metrics with per-check-name breakdowns

Clean feature addition. The approach of generating per-check SQL expressions via the observer is sound. A few items below.

Comment thread src/databricks/labs/dqx/metrics_observer.py
Comment thread src/databricks/labs/dqx/metrics_observer.py
Comment thread src/databricks/labs/dqx/engine.py Outdated
Comment thread tests/integration/test_summary_metrics.py
Comment thread tests/unit/test_observer.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

@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 15, 2026
@codecov

codecov Bot commented Apr 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.03%. Comparing base (0c7d688) to head (c5b9ab0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1097      +/-   ##
==========================================
+ Coverage   91.97%   92.03%   +0.06%     
==========================================
  Files         101      101              
  Lines        9408     9418      +10     
==========================================
+ Hits         8653     8668      +15     
+ Misses        755      750       -5     
Flag Coverage Δ
anomaly 53.97% <27.77%> (?)
anomaly-serverless 53.86% <27.77%> (?)
integration 50.14% <83.33%> (?)
integration-serverless 50.31% <83.33%> (?)
unit 55.62% <83.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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]: Tests run metrics summary [FEATURE]: Extend summary metrics with check name

2 participants