Skip to content

Do not match a missing column's null with negated predicates - #4614

Open
DE-Dobby wants to merge 2 commits into
apache:mainfrom
DE-Dobby:fix-missing-column-null-predicates
Open

DE-Dobby wants to merge 2 commits into
apache:mainfrom
DE-Dobby:fix-missing-column-null-predicates

Conversation

@DE-Dobby

@DE-Dobby DE-Dobby commented Dec 4, 2026

Copy link
Copy Markdown

Closes #4613

Rationale for this change

After add_column, != and not like on the new column returned every row of files written before the column existed, but not rows with an explicit null, so rewriting those files changed the result.

For a column missing from the file the predicate was evaluated in Python against None, where None != 'ok' is true. A null missing value now only decides IsNull / NotNull, as #4278 did for null partition values. Negations are pushed down with rewrite_not first so not x = 'a' behaves like x != 'a'. NotIn is left alone since the PyArrow filter keeps nulls for it too (#3918).

Are these changes tested?

Yes. Unit tests for each predicate on a missing column, and a scan test that compares results before and after the files are rewritten.

Are there any user-facing changes?

Yes. These scans no longer return rows from files that lack the column.

AI disclosure: drafted with Claude Code; I reviewed the change and the tests.

After add_column, a scan with `!=` or `not like` returned every row of the
files written before the column existed, but not rows that store an explicit
null, so rewriting those files changed the result of the same scan.

A null missing value now decides only IsNull and NotNull, as a null partition
value does since apache#4278. Negations are pushed down before translating so that
Not(EqualTo) behaves like NotEqualTo. NotIn is unchanged because the PyArrow
filter keeps nulls for it as well.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @DE-Dobby! Nice fix, the scans now agree before and after a rewrite, closes #4613 🙌. Verified that count() and to_arrow() agree for != and not in across the rewrite, and that the single-literal NotIn collapse to NotEqualTo behaves the same on files with and without the column. Nit: in tests/expressions/test_visitors.py (the cases loops around line 1921) could you use @pytest.mark.parametrize instead of a loop?

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@DE-Dobby

DE-Dobby commented Dec 4, 2026

Copy link
Copy Markdown
Author

Thanks for the review! Switched both tests to pytest.mark.parametrize. The Windows failure is test_cache_expires_entries (#4602), unrelated to this change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

!= on a column added later returns rows from older files

2 participants