Repository navigation
Core: Bound IsNull and NotNull on the full field path - #4513
Open
Anurag-S1ngh wants to merge 1 commit into
Open
Anurag-S1ngh wants to merge 1 commit into
Anurag-S1ngh wants to merge 1 commit into
Conversation
IsNull and NotNull folded a required field to AlwaysFalse and AlwaysTrue using only the leaf field. A required leaf under an optional struct can still be absent, which made plan_files drop matching files. Fold at bind time only when the field and every ancestor are required.
This was referenced Nov 30, 2026
rahulsmahadev
left a comment
Contributor
There was a problem hiding this comment.
Thanks @Anurag-S1ngh! On files that contain the struct, all four null predicates now match a pyarrow oracle in scans, count() and delete().
I'd recommend also covering files written before the struct was added: _ColumnNameTranslator evaluates the missing field against Schema(field), where the required child looks top-level, so IsNull still folds to false:
table = catalog.create_table("ns.t", schema=Schema(NestedField(1, "id", LongType())))
table.append(pa.table({"id": [1, 2]}))
with table.update_schema() as update:
update.add_column("s", StructType(NestedField(3, "x", LongType(), required=True)))
table.scan(row_filter=IsNull("s.x")).to_arrow()["id"] # [] here, expected [1, 2]; NotNull gives [1, 2]Binding an optional copy of the field there fixed it in a scratch copy.
A couple of smaller suggestions:
- This also stops
delete("s.x == 5")from dropping ans = nullrow in the same file, as main does; worth a line in the description and a test. - A required struct between the optional one and the leaf would catch a check that stops at the direct parent.
- #4068, by the author of #4067, has the same code and was closed by the stale bot on Nov 27; maybe link it and add them as co-author.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Closes #4067.
IsNullandNotNullfolded a required field toAlwaysFalseandAlwaysTrueusing only the leaf field'srequiredflag. A required leaf can still be absent when an ancestor struct is null, so a scan could prune every file and return no rows.The fold now happens at bind time and only when the field and every ancestor on its path to the root are required.
BoundIsNullandBoundNotNullno longer fold on direct construction.Are these changes tested?
Yes. Added coverage for the schema path check, for binding a required leaf under an optional ancestor and a required ancestor, and for direct construction not folding. Also added a scan regression test that appends a null optional struct with a required child and checks that
IsNull("s.x")keeps the file andNotNull("s.x")returns no rows.tests/test_schema.py tests/expressions: 965 passedtests/io/test_pyarrow.py -m unit: 267 passed, 1 skippedtests/table/test_init.py -m unit: 184 passedAre there any user-facing changes?
No API changes. Scans that filter on a required field under an optional ancestor now return the correct rows instead of no rows.