← Back to Pull requests

[bug] Fix filter-pushdown correctness bugs in DNF/set visitors #87

Closed
unknown closed this pull request without merging on Oct 22, 2026 18:26 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 12:55 UTC
Author

Description

The DNF (dnf_visitor) and valid-value (set_visitor) conversions turn a Polars predicate into a filter that is applied before data is read. That filter may keep extra rows, since the full predicate runs afterwards, but it must never drop a row the predicate keeps. Several conversions broke this rule, so scan_delta and pushdown_combine could return fewer rows than the predicate selects:

  • NOT over a relaxed result. An AND with an unconvertible side is relaxed to its convertible side, which is a superset. Negating that superset gives a subset, which drops rows. NOT (including ternary negation and the horizontal AND/OR forms) now only negates results marked safe and otherwise pushes no filter. set_visitor had the same problem: NOT now excludes values only when the inner result is exact.

  • eq_missing / ne_missing were mapped to = / !=. ne_missing(v) keeps nulls, and eq_missing(None) / ne_missing(None) mean is null / is not null.

  • is_in(..., nulls_equal=True): a null-matching is_in now emits in OR is null, and its negation is no longer pushed down.

  • Casts on the column were stripped. pl.col("a").cast(pl.Int8, wrap_numerical=True) == 1 pushed a == 1 and dropped a == 257. A cast is now looked through only when the schema shows it keeps values and order: identity, integer widening, or decimal widening at the same scale. Dtype identity is strict, so Datetime("us") -> Datetime("ms") does not count.

  • when(P).then(T).otherwise(F) dropped rows where P is null. Polars takes the otherwise branch for those rows, so they are now included.

  • str.contains defaults to a regex search, but the pattern was escaped as a literal. Only literal=True patterns are escaped now.

  • Comparisons with the literal on the left (lit(1) < col) are now flipped instead of failing to convert, and horizontal OR no longer drops unconvertible branches.
  • Each fix has a regression test that fails on main. Several tests check the pushed filter against the real predicate on data containing nulls.

    Things to note for review:

  • Callers that convert without a schema (pushdown_combine, partition pruning, pushdown_unpivot) now refuse every column cast. The result is still correct but may prune less.

  • Ternary DNFs now contain extra is null clauses, so the expected outputs of several existing ternary tests changed.

  • Not fixed here: range_visitor still uses extract_column_name, which looks through lossy casts such as Datetime("us") -> Datetime("ms"). It intentionally looks through Datetime -> Date for date-range pruning, so a correct fix needs to widen bounds for truncating casts. I'd rather do that in a separate PR.
  • Type of Change

  • Bug fix

  • New feature

  • Documentation update

  • Refactor / code cleanup

  • CI / build configuration

  • Other (describe below)
  • Checklist

  • Linting passes (make lint): make lint-py passed. No Rust or docs changes, so lint-rs and lint-docs were not run.

  • Tests pass (make test): make test-py passed (2186 passed, 73 skipped, 6 xfailed). No Rust changes, so test-rs was not run.

  • New tests added for new functionality

  • Documentation updated (if applicable)

  • Changelog / version bump (if applicable)
  • Diff: 413 lines (+309 / -104) across 5 files Reviewer: timkpaine Review duration: 331m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 413 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.361
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #87"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.9% (MEDIUM) · Higher = larger blast radius
    44.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.7% · Safe to merge
    17.7%