Repository navigation
Core: Bound IsNull and NotNull on the full field path - #4513
Anurag-S1ngh wants to merge 5 commits 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.
rahulsmahadev
left a comment
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.
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.
|
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.
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.Fields that are missing from a data file are now evaluated as optional in
_ColumnNameTranslator, soIsNullon 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