Skip to content

Core: Bound IsNull and NotNull on the full field path - #4513

Open
Anurag-S1ngh wants to merge 5 commits into
apache:mainfrom
Anurag-S1ngh:fix/4067-isnull-ancestor-nullability
Open

Anurag-S1ngh wants to merge 5 commits into
apache:mainfrom
Anurag-S1ngh:fix/4067-isnull-ancestor-nullability

Conversation

@Anurag-S1ngh

@Anurag-S1ngh Anurag-S1ngh commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Closes #4067.

IsNull and NotNull folded a required field to AlwaysFalse and AlwaysTrue using only the leaf field's required flag. 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. BoundIsNull and BoundNotNull no longer fold on direct construction.

Fields that are missing from a data file are now evaluated as optional in _ColumnNameTranslator, so IsNull on a required field added by schema evolution keeps files written before the field existed.

Are these changes tested?

Yes. Added coverage for the schema path check, for binding a required leaf under an optional ancestor, a required ancestor, and a required struct between an optional ancestor and the leaf, and for direct construction not folding. Also added regression tests for a scan of a file written before a required struct field was added, and for delete("s.x == 5") keeping a row whose optional struct is null. The delete result differs from main, which drops that row.

Are there any user-facing changes?

No API changes. Scans and deletes that filter on a required field under an optional ancestor now treat rows with a null ancestor as null instead of dropping them.

Also supersedes #4068, which carried the same fix and was closed by the stale bot.

Co-authored-by: seitzdom 39090287+dominikandreasseitz@users.noreply.github.com

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.

@rahulsmahadev rahulsmahadev 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 @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 an s = null row 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.

A required field absent from a data file is projected as null, but _ColumnNameTranslator evaluated the predicate against Schema(field), which makes the leaf look top-level and required, so IsNull folded to false and the file was dropped. Evaluate against an optional copy of the field instead.
Add tests for a path with an optional struct, a required struct, and a required leaf, so a check that stops at the direct parent is caught.
A row with a null struct must be kept when the delete filter targets a required child of that struct.
@Anurag-S1ngh

Copy link
Copy Markdown
Contributor Author

Added the missing field path: _ColumnNameTranslator now evaluates absent fields against an optional copy, so IsNull no longer folds for files written before the struct existed. Added the scan test for that case and the required struct between the optional ancestor and the leaf.

Also added the delete test: delete("s.x == 5") keeps the row whose struct is null, and the description notes the behavior change from main.

Linked #4068 and added seitzdom as co-author.

Without the folding __new__ methods, ty infers a constructor that rejects a positional term, so it reports too-many-positional-arguments. Use the term keyword in the calls.

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.

IsNull/NotNull binding ignores ancestor nullability for required nested fields

2 participants