Skip to content

Fixes #35274: count no failed rows for an open between bound and compare boolean sets as booleans - #35276

Merged
TeddyCr merged 6 commits into
2.0from
fix/dq-test-parameters-2.0
Oct 14, 2026
Merged

TeddyCr merged 6 commits into
2.0from
fix/dq-test-parameters-2.0

Conversation

@Shreyansh100704

@Shreyansh100704 Shreyansh100704 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #35274

I fixed two data quality runners on 2.0 that reported wrong results:

  • Open between bounds: a side of a columnValuesToBeBetween / columnValueLengthsToBeBetween window that is unset (or -inf/+inf) now excludes no row. Before, both sides open produced an empty filter list, the failed-row count ran without a WHERE, and the test passed while reporting every row as failed.
  • Boolean sets: allowed/forbidden values on a BOOLEAN column are parsed by column type, so "true" / "false" compare as booleans. Before, literal_eval kept them as strings and Databricks aborted the test on the type mismatch.

Type of change:

  • Bug fix

High-level design:

  • validations/utils.py: is_unbounded(bound) (None, or a float that is infinite; a datetime window is always a real bound) and parse_set_values(raw, column_type) (literal_eval, then "true"/"false" to booleans when the column is boolean).
  • profiler/orm/registry.py: is_boolean(_type) for both a SQLAlchemy type and an OpenMetadata DataType, next to is_date_time.
  • mixins/sqa_validator_mixin.py: _count_rows_outside(runner, column, expression, min_bound, max_bound) builds the lt/gt filters from the bounded sides only and returns 0 when neither side is bounded. Both SQLAlchemy between validators use it, and their filter() uses is_unbounded, so the failed-row sample and the count agree.
  • base_test_handler.py: get_set_param_value(param_name) reads a set typed by the validated column; the six set validators (base, SQLAlchemy, pandas, InSet and NotInSet) call it instead of literal_eval.
  • Unchanged on purpose: the dimensional BetweenBoundsChecker already skips infinite bounds; the pandas between validators already count 0 rows outside an open window; the failed-row sample is only fetched for a Failed result, which an all-open window cannot produce.

Tests:

Use cases covered

  • A columnValuesToBeBetween test with no bounds: Success, 80 passed / 0 failed on the sample DB (was 0 / 80).
  • A columnValueLengthsToBeBetween test with no bounds: Success, 80 / 0 (was 0 / 80). The one-sided no_min case is unchanged.
  • columnValuesToBeInSet on a BOOLEAN column with ["true", "false"]: same result as [True, False] (Success, 70 / 10).
  • String columns keep string sets; Python literals on a boolean column are kept.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files updated: tests/unit/observability/data_quality/conftest.py, tests/unit/observability/data_quality/test_validations_databases.py (..._no_bounds x2, test_case_column_value_in_set_boolean_strings), tests/unit/observability/data_quality/validations/test_utils.py (test_is_unbounded, parse_set_values and is_boolean cases). Each new test failed before the change.
  • Runs: tests/unit/observability/data_quality + tests/unit/data_quality: 404 passed. tests/unit/observability: 942 passed, 2 skipped; 1 failure in test_sqa_profiler_interface.py::test_get_all_metrics only under -n auto (shared SQLite table race, 8/8 pass serially) and 3 collection errors for the databricks module not installed locally. tests/unit/sampler: 95 passed.
  • Coverage %: not measured.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable (no connector changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  1. Local 2.0.6 stack, Postgres table of 100 rows registered through the metadata workflow.
  2. columnValuesToBeBetween with dynamic assertion and no learned bound (open window): before 0 passed / 100 failed, after 100 passed / 0 failed.
  3. Ran the other tests on that table with the patched package (not-null, unique, lengths, row count, custom SQL, in-set with matchEnum): each result matched the data.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

Summary by Gitar

  • Test definitions:
    • Rewrote tableCustomSQLQuery strategy and columnValuesToBeInSet matchEnum descriptions in the JSON definitions
  • Migrations:
    • Added 2.0.6 Postgres and MySQL data migrations that apply the new definition descriptions

This will update automatically on new commits.

@Shreyansh100704
Shreyansh100704 requested a review from a team as a code owner October 12, 2026 18:39
@Shreyansh100704
Shreyansh100704 requested review from stout-yeoman and removed request for a team October 12, 2026 18:39
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Oct 12, 2026

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

Reviewed at 39f86c3.

Both diagnoses in #35274 are right, and the between-bounds fix is correct. The new _no_bounds cases run against real SQLite and fail without the change. Two things block merge:

  1. CI is red because of this change: basedpyright on sqa_validator_mixin.py:197 (inline).
  2. Regression on datalake: pandas infers string "True"/"False" columns as BOOLEAN, so the new set parsing turns string sets into bools that no longer match (inline on get_set_param_value, with a repro).

Also: this targets 2.0, but main has both bugs (literal_eval in the set validators, the empty-filter between count). Is a main PR planned?

return self.get_test_case_param_value(
self.test_case.parameterValues, # type: ignore
param_name,
partial(utils.parse_set_values, column_type=self.get_column().type),

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.

Regression on the pandas/datalake path. For pandas, get_column().type is not the declared column type. It is inferred by GenericDataFrameColumnParser.fetch_col_types, which runs ast.literal_eval on the values of object-dtype columns. As a result, a column of the strings "True"/"False" is reported as DataType.BOOLEAN, and parse_set_values turns the user's string set into Python bools that no longer match the data:

df = pd.DataFrame({"s": ["True", "False", "True"]})   # dtype object, real strings
GenericDataFrameColumnParser.fetch_col_types(df, "s")  # -> DataType.BOOLEAN
df[~df.s.isin([True, False])].shape                    # (3, 2)  all rows fail (this PR)
df[~df.s.isin(["True", "False"])].shape                # (0, 2)  before this PR

So on a datalake source, columnValuesToBeInSet(["True","False"]) with matchEnum goes from Success to failing every row, and NotInSet goes from catching the values to catching none. Suggest only converting when the data really is boolean: on pandas, check the dataframe dtype is bool, or keep the conversion on the SQLAlchemy side where the type comes from the engine. A pandas case for this belongs in test_validations_datalake.py.

Also, PandasValidatorMixin.get_column() does next(dfs()), which loads the first chunk. This helper now calls it again in _get_test_parameters, in the dimensional path and in filter(), which means extra object-store reads per test on datalake. Passing in the column the caller already resolved avoids that.

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.

Fixed by keeping the conversion on the SQLAlchemy side, as you suggested. get_set_param_value now asks a new get_set_values_type() hook, which resolves through the mixins the same way get_column does. SQAValidatorMixin returns the engine's column type. PandasValidatorMixin returns None, so pandas sets stay as written and the helper no longer loads a chunk.

filters = [
(expression, op, bound) for op, bound in (("lt", min_bound), ("gt", max_bound)) if not is_unbounded(bound)
]
return (

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.

This is what turns python / Unit Tests & Static Checks (3.10) red: basedpyright reports Type "Unknown | Literal[0] | None" is not assignable to return type "int" at 197:16, because _compute_row_count_between returns Optional. Either annotate -> Optional[int] (callers already put it in failed_rows) or coalesce with or 0. A new violation fails CI even though the baseline exists.

The logic itself looks right: one-sided windows keep their single filter, and a datetime bound stays bounded through is_unbounded. That matches the old not isinstance(..., (int, float)) guard in columnValuesToBeBetween.

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.

Fixed: annotated -> Optional[int], which matches what callers already put in failed_rows.

return [_as_boolean(value) for value in values] if is_boolean(column_type) else values


def _as_boolean(value):

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.

Only true/false (case-insensitive) are mapped. "1"/"0", "t"/"f" and "yes"/"no" stay strings, so Databricks will still abort on a set like ["1","0"]. That's fine if it's deliberate, but the parse_set_values docstring should say so. Separately, if allowedValues ever parses to a bare string ('"true"'), the comprehension iterates over its characters. Guarding with isinstance(values, (list, tuple, set)) would make that a clear error instead.

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.

Deliberate: only true/false (any case) are mapped, since that's what the UI and generated tests write. The parse_set_values docstring now says so, and that "1"/"0", "t"/"f" and "yes"/"no" stay as written.

self.ALLOWED_VALUES,
literal_eval,
)
allowed_values = self.get_set_param_value(self.ALLOWED_VALUES)

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.

Nit: _get_test_parameters() runs before the try in _run_validation, and it now calls get_column(). A missing or renamed column used to hit the local except (ValueError, RuntimeError) and return Aborted with allowedValueCount=None. Now it escapes to the catch-all in TestSuiteInterface.run_test_case. The result is still Aborted, but it comes with a logger.exception stack trace and an empty result-values list. Moving the _get_test_parameters() call inside the try keeps the old behavior. The same applies to columnValuesToBeNotInSet.py:56.

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.

Agreed. Moved _get_test_parameters() inside the try in both columnValuesToBeInSet and columnValuesToBeNotInSet, so a missing column is Aborted through the local handler again.

Check if _type is a boolean, as a sqlalchemy type or an OpenMetadata DataType
"""
return (
_type.value == DataType.BOOLEAN.value if isinstance(_type, DataType) else issubclass(_type.__class__, Boolean)

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.

Nit: _type == DataType.BOOLEAN and isinstance(_type, Boolean) are equivalent and match how the neighboring helpers read.

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.

Done

None,
),
(
"test_case_column_value_in_set_boolean_strings",

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.

Good regression test: on SQLite, 'true' IN (...) against the 0/1 boolean column counts 0, so this fails without the fix. Coverage is only on the SQLAlchemy InSet path, though. There's nothing for NotInSet and nothing on pandas, which is where the regression above sits. Could you add columnValuesToBeNotInSet with ["true"] here, and the string-booleans pandas case in test_validations_datalake.py?

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.

Added test_case_column_values_not_in_set_boolean_strings: NotInSet with ["true"] on the boolean column, giving Failed with 40 forbidden out of 80 rows. The pandas string-boolean case is in test_validations_datalake.py

@Shreyansh100704
Shreyansh100704 requested a review from a team as a code owner October 13, 2026 10:24
@gitar-bot

gitar-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Changing open-bound row counts and boolean set parsing could incorrectly mark data-quality tests as passing or failing for affected columns.

Fixes two data quality runners on 2.0: open between bounds now exclude no rows, so the failed-row count no longer reports every row as failed, and boolean allowed/forbidden sets are parsed as booleans for BOOLEAN columns. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

@TeddyCr
TeddyCr merged commit 60777bd into 2.0 Oct 14, 2026
89 of 91 checks passed
@TeddyCr
TeddyCr deleted the fix/dq-test-parameters-2.0 branch October 14, 2026 16:19

This branch was previously deployed

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

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data quality: open between bounds count every row as failed, and boolean sets compare as strings

2 participants