← Back to Pull requests

Keep rows where a delete filter evaluates to null #4219

Open
Rahul-cs50 opened this pull request with 130 lines diff across 4 files
View on GitHub
Rahul-cs50 Rahul-cs50 commented on Oct 31, 2026 07:01 UTC
Author

Closes #4184

Rationale for this change

When delete() (and overwrite() with an overwrite_filter) has to rewrite a data file, it keeps the rows that _expression_to_complementary_pyarrow selects. That filter was NOT f, OR'd with c IS NULL for every column c that f reads without a null check. Under pyarrow's three-valued logic that goes wrong both ways when a column is null:

  • NOT f is null where f is null, so the row is dropped even though f did not match it: x=2 in the issue (p == 2, v null) is deleted by (p == 1 AND v IS NULL) OR (p == 2 AND v == 'c').

  • c IS NULL keeps a row whenever c is null, even where f is still true: p == 1 OR v == 'c' keeps x=1 (p == 1, v null).
  • A row should be deleted exactly where f is true, which are the rows scan(row_filter=f) returns. The complement is now NOT coalesce(f, false). The NaN handling (OR is_nan(c) for columns the filter does not NaN-check) is left as it was.

    Are these changes tested?

    Yes. test_delete_and_overwrite_filter_with_null in tests/catalog/test_catalog_behaviors.py runs the issue's two filters plus v != 'c' and NOT (v == 'c') through delete() and overwrite() on every local catalog, and checks that the rows left are the ones scan(row_filter=...) does not return. It fails on main and passes with this change. test_expression_to_complementary_pyarrow is updated for the new expression. Unit tests in tests/io, tests/table, tests/catalog and tests/expressions: 2658 passed (the only failures are the four Kerberos tests in test_hive.py, which need the hive-kerberos extra I did not install). ruff check and ruff format --check are clean.

    Are there any user-facing changes?

    delete() and overwrite(..., overwrite_filter=...) no longer delete rows the filter does not match, or keep rows it does, when a column the filter reads is null.

    Diff: 130 lines (+56 / -74) across 4 files Reviewer: developer-rpai Review duration: 47151m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.44) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.44 · 130 lines diff across 4 files
    0.44
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 3 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    89%
    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.292
    Real PR Conversation Timeline
    7 items
    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 31, 2026 07:01 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

    developer-rpai developer-rpai commented on Nov 12, 2026 19:05 UTC
    Reviewer

    Nice writeup, and checking against scan(row_filter=...) is the right oracle. Wrapping in coalesce(..., False) works well with Arrow's kleene and/or.

    1. I think the NaN branch in _expression_to_complementary_pyarrow (pyiceberg/io/pyarrow.py around L1125) now has the same problem the null branch had. OR is_nan(col) keeps a row whenever col is NaN, even if the filter is true through another column. Take p == 1 OR d > 0 with p = 1 and d = NaN: Arrow gives false for NaN > 0 (not null), so the filter is true and scan returns the row, but the complement still keeps it. d != 5 is the same, since NaN != 5 is true in Arrow. Could you add a float column with a NaN to test_delete_and_overwrite_filter_with_null and check whether the NaN terms are still needed at all? Fine as a follow-up if you'd rather keep this PR to nulls.
    2. Minor: _NullNaNUnmentionedTermsCollector still fills null_unmentioned_bound_terms, but nothing reads it anymore. You could drop that half or leave a note.
    3. The updated expected repr in tests/io/test_pyarrow_visitor.py is tied to pyarrow's expression formatting. A behavior assertion would be less brittle across pyarrow versions, but that's a nit.

    Rahul-cs50 Rahul-cs50 commented on Nov 16, 2026 11:23 UTC
    Author

    Thanks for the careful review! Good catch on the NaN branch. I'd like to keep this PR to nulls and handle NaN in a follow-up, with a NaN float column added to that test. Here I'll drop the unused null half of the collector and switch the repr check to a behaviour assertion.

    Rahul-cs50 Rahul-cs50 commented on Nov 17, 2026 10:58 UTC
    Author

    Pushed 88075cd with the two changes from your review: the collector now tracks only NaN terms (renamed _NaNUnmentionedTermsCollector), and test_expression_to_complementary_pyarrow checks which rows the complement keeps on a small table instead of the expression repr. The NaN branch stays for the follow-up PR.

    developer-rpai developer-rpai approved these changes on Nov 20, 2026 06:42 UTC
    Approved Reviewer

    Thanks, 88075cd covers both. Checking which rows the complement keeps reads much better than the repr, and row 5 shows the null case directly. LGTM. Tiny optional nit: the two test_collect_null_nan_unmentioned_terms tests could drop "null" from their names now.

    Rahul-cs50 Rahul-cs50 commented on Nov 21, 2026 07:11 UTC
    Author

    Thanks for the approval! Renamed both to test_collect_nan_unmentioned_terms* in 6cdee7a.

    Assignees
    Rahul-cs50 Rahul-cs50
    Labels
    risk: low confidence: 89.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: 43.5% (MEDIUM) · Higher = larger blast radius
    43.5%
    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: 89.5% · Lower = rushed or shallow review
    89.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: 4.6% · Safe to merge
    4.6%