-
Notifications
You must be signed in to change notification settings - Fork 146
Refactor profiler column metrics into an extensible registry #1384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mwojtyczka
merged 31 commits into
databrickslabs:main
from
IvannKurchenko:feature/profiler_additional_metrics
Sep 11, 2026
Merged
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
7a7e092
first draft
IvannKurchenko 268ad0c
linter fixes
IvannKurchenko c68523f
profiling metrics docs
IvannKurchenko 1e37af9
tests
IvannKurchenko 7b22dfc
Clean up blank lines in profiler unit tests
IvannKurchenko fc6cc28
integration test of metric via public API
IvannKurchenko 8224e1c
Merge branch 'main' into feature/profiler_additional_metrics
IvannKurchenko 7c4fc5f
Merge branch 'main' into feature/profiler_additional_metrics
mwojtyczka e86cec8
Merge branch 'main' into feature/profiler_additional_metrics
mwojtyczka e4ea9bd
code review comments addressed
IvannKurchenko 9b10735
conflicts wigh main resolved
IvannKurchenko da2e916
code review comments addressed
IvannKurchenko 5457f02
better type hints
IvannKurchenko 49e0877
Merge branch 'main' into feature/profiler_additional_metrics
IvannKurchenko 0f68549
Merge branch 'main' into feature/profiler_additional_metrics
IvannKurchenko 9931ddc
Merge branch 'main' into feature/profiler_additional_metrics
mwojtyczka fe680d6
Merge branch 'main' into feature/profiler_additional_metrics
IvannKurchenko 998a66d
code review comments addressed
IvannKurchenko 14ebbb4
Merge branch 'feature/profiler_additional_metrics' of github.com:Ivan…
IvannKurchenko b804e05
Merge branch 'main' into feature/profiler_additional_metrics
mwojtyczka 2507246
code review comments addressed
IvannKurchenko 42a808c
Merge branch 'feature/profiler_additional_metrics' of github.com:Ivan…
IvannKurchenko ae7e302
Merge branch 'main' into feature/profiler_additional_metrics
IvannKurchenko fe60249
Merge branch 'main' into feature/profiler_additional_metrics
mwojtyczka 12ede78
Merge branch 'main' into feature/profiler_additional_metrics
IvannKurchenko e732ce3
code review comments fixes
IvannKurchenko 863ecf2
Merge branch 'feature/profiler_additional_metrics' of github.com:Ivan…
IvannKurchenko 0b94233
docs(profiler): correct summary() percentile metric keys (25%/50%/75%)
mwojtyczka 993583f
Merge branch 'main' into feature/profiler_additional_metrics
mwojtyczka 3103199
docs(profiler): clarify custom metric/builder interfaces and cross-re…
mwojtyczka a88902e
test(profiler): cover register_profile_builder end-to-end and metric …
mwojtyczka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/databricks/labs/dqx/profiler/profiler_column_metrics.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import logging | ||
| from collections.abc import Callable | ||
|
|
||
| from pyspark.sql import Column | ||
| from pyspark.sql import functions as F | ||
| from pyspark.sql import types as T | ||
|
|
||
| from databricks.labs.dqx.profiler.common import is_text | ||
|
|
||
|
|
||
| DQProfileColumnMetricFunc = Callable[[T.StructField, str], Column | None] | ||
|
mwojtyczka marked this conversation as resolved.
|
||
| PROFILE_COLUMN_METRIC_REGISTRY: dict[str, DQProfileColumnMetricFunc] = {} | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def register_profile_column_metric( | ||
| profile_column_metric_type: str, | ||
| ) -> Callable[[DQProfileColumnMetricFunc], DQProfileColumnMetricFunc]: | ||
| """ | ||
| Registers data quality profile column metric function. The function that may create a column metric depending on | ||
| the column type of the input column or other internal logic. Result column is used in an aggregation function | ||
| resulting in a single value for a given column and data frame. The aggregation value will be used further to at the profiling | ||
| stage to supply common column level metrics to construct corresponding builders. | ||
|
|
||
| Expected signature of the function is as follows: | ||
| (field,column_label) -> Column | None | ||
| where: | ||
| - field: struct field of the profiling column | ||
| - column_label: name of the column that is present in the dataframe to be aggregated | ||
| The function may return *None* if aggregation is not applicable. | ||
|
|
||
| Args: | ||
| profile_column_metric_type: Key under which the metric is registered and exposed to profile builders. | ||
| """ | ||
|
|
||
| def wrapper(metric_func: DQProfileColumnMetricFunc) -> DQProfileColumnMetricFunc: | ||
| if profile_column_metric_type in PROFILE_COLUMN_METRIC_REGISTRY: | ||
| logger.warning(f"Overwriting profile column metric registered as '{profile_column_metric_type}'") | ||
| PROFILE_COLUMN_METRIC_REGISTRY[profile_column_metric_type] = metric_func | ||
| return metric_func | ||
|
|
||
| return wrapper | ||
|
|
||
|
|
||
| @register_profile_column_metric("empty_count") | ||
| def empty_count(field: T.StructField, column_label: str) -> Column | None: | ||
| """ | ||
| Profiling column metric for empty count. Applicable for text columns only, otherwise returns literal *0* for | ||
| backward compatibility. | ||
| """ | ||
| return F.count_if(F.col(column_label) == "") if is_text(field.dataType) else F.lit(0) | ||
|
mwojtyczka marked this conversation as resolved.
|
||
|
|
||
|
|
||
| @register_profile_column_metric("count_distinct") | ||
| def count_distinct(_field: T.StructField, column_label: str) -> Column | None: | ||
| """ | ||
| Profiling column metric for count distinct. Applicable for all columns. | ||
| """ | ||
| return F.countDistinct(column_label) | ||
|
|
||
|
|
||
| @register_profile_column_metric("count_non_null") | ||
| def count_non_null(_field: T.StructField, column_label: str) -> Column | None: | ||
| """ | ||
| Profiling column metric for count not null values. Applicable for all columns. | ||
| """ | ||
| return F.count(column_label) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.