Is there an existing issue for this?
Problem statement
I have some checks that utilize check_funcs.is_aggr_equal and have been trying to figure out how to round the aggregation as I keep getting warnings that are strictly due to rounding diffs
Example warning:
0: {"name": "ensure_numerator_sum_to_1", "message": "Sum value 0.9999999999999999 in column 'Numerator_Percent' per group of columns 'profile_type, concatenated_keys, Segmentation' is not equal to limit: 1", "columns": ["Numerator_Percent"], "filter": null, "function": "is_aggr_equal", "run_time": "2026-01-20T15:52:16.486Z", "run_id": "c4e9c0be-18bf-4cf5-b3a9-fefb77950a2c", "user_metadata": {}}
Here is the check itself:
DQDatasetRule(
name="ensure_denom_sum_to_1",
criticality="warn",
check_func=check_funcs.is_aggr_equal,
column = "Denominator_Percent",
check_func_kwargs={
"group_by": ['profile_type', 'concatenated_keys', 'Segmentation'],
"aggr_type": "sum",
"limit": 1}
),
]
Proposed Solution
It seems like the _is_aggr_compare function could add an optional rounding:
|
def _is_aggr_compare( |
|
column: str | Column, |
|
limit: int | float | str | Column, |
|
aggr_type: str, |
|
aggr_params: dict[str, Any] | None, |
|
group_by: list[str | Column] | None, |
|
row_filter: str | None, |
|
compare_op: Callable[[Column, Column], Column], |
|
compare_op_label: str, |
|
compare_op_name: str, |
|
) -> tuple[Column, Callable]: |
|
""" |
|
Helper to build aggregation comparison checks with a given operator. |
|
|
|
Constructs a condition and closure that verify whether an aggregation on a column |
|
(or groups of columns) satisfies a comparison against a limit (e.g., greater than). |
|
|
|
Args: |
|
column: Column name (str) or Column expression to aggregate. |
|
limit: Numeric value, column name, or SQL expression for the limit. String literals must be single quoted, e.g. 'string_value'. |
|
aggr_type: Aggregation type. Curated functions include 'count', 'sum', 'avg', 'min', 'max', |
|
'count_distinct', 'stddev', 'percentile', and more. Any Databricks built-in aggregate |
|
function is supported (will trigger a warning for non-curated functions). |
|
aggr_params: Optional dictionary of parameters for aggregate functions that require them |
|
(e.g., percentile functions need {"percentile": 0.95}). |
|
group_by: Optional list of columns or Column expressions to group by. |
|
row_filter: Optional SQL expression to filter rows before aggregation. |
|
compare_op: Comparison operator (e.g., operator.gt, operator.lt). |
|
compare_op_label: Human-readable label for the comparison (e.g., 'greater than'). |
|
compare_op_name: Name identifier for the comparison (e.g., 'greater_than'). |
|
|
|
Returns: |
|
A tuple of: |
|
- A Spark Column representing the condition for the aggregation check. |
|
- A closure that applies the aggregation check logic. |
|
|
|
Raises: |
|
InvalidParameterError: If an aggregate returns non-numeric types or is not found. |
|
MissingParameterError: If required parameters for specific aggregates are not provided. |
Potentially something like this being added to the aggr_expr:
# Apply rounding if specified
if round_decimals is not None:
aggr_expr = F.round(aggr_expr, round_decimals)
Additional Context
No response
Is there an existing issue for this?
Problem statement
I have some checks that utilize
check_funcs.is_aggr_equaland have been trying to figure out how to round the aggregation as I keep getting warnings that are strictly due to rounding diffsExample warning:
Here is the check itself:
Proposed Solution
It seems like the
_is_aggr_comparefunction could add an optional rounding:dqx/src/databricks/labs/dqx/check_funcs.py
Lines 2755 to 2793 in 45da959
Potentially something like this being added to the aggr_expr:
Additional Context
No response