Repository navigation
Apply initial defaults under present struct parents - #4480
Closed
rahulsmahadev wants to merge 4 commits into
Closed
rahulsmahadev wants to merge 4 commits into
rahulsmahadev wants to merge 4 commits into
Conversation
A field added under an optional struct with an initial default was folded to that default for the whole file, so rows whose struct is NULL matched as if the field were present. Such predicates now read the field as NULL under a NULL ancestor struct, and a NOT over them (or over != and NOT IN) is pushed into its complement. Arrow paths are built from field IDs, so a struct whose name contains a dot resolves after a rename. Co-authored-by: Isaac <[email protected]>
The expression evaluator and Arrow agree on NULL for these predicates, as for = and IN, so a row under a NULL struct no longer matches the default. NOT over NOT STARTS WITH and NOT NAN is pushed into STARTS WITH and IS NAN. Drop the test cases that asserted main's results for top-level and required-only NOT, which a file storing the NULLs and Java do not return, and the visitor test that did not reach the new code. Restore the comment on the rewrite_not line. Co-authored-by: Isaac <[email protected]>
Co-authored-by: Isaac <[email protected]>
Contributor
Author
|
@kevinjqliu could you take a look when you have a chance? Thanks! |
Restore NOT (d > 4) and NOT (rq.c2 > 4): without an optional struct ancestor, NOT keeps its result on a missing field, as in main and Java. Without these cases, removing the optional-ancestor check in _is_missing_nested_field passed every test. Also filter on a column named a.b and on a present field under the renamed new.pt struct; both raise ArrowInvalid on main. Co-authored-by: Isaac <[email protected]>
Contributor
Author
|
Closing this one. It grew too many special cases around the constant fold; a smaller fix is to skip the fold for a missing field under an optional struct and filter the projected batch. |
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
Bug: for a field added under an optional struct with an initial default, the translator folds the default over the whole file, so a row whose struct is NULL is treated as having the default. Here
ptis an optional struct, row 2 hasptNULL, andpt.cwas added withinitial-default5:Fix: for =, IN, NOT IN, <, <=, >, >=, IS NULL, IS NOT NULL, STARTS WITH and IS NAN,
translate_column_namesmatches each row by its optional ancestor structs: the default when all of them are present, NULL otherwise. These are the predicates for which PyIceberg's expression evaluator and Arrow give the same result on NULL. A NOT over one of them, or over !=, NOT STARTS WITH or NOT NAN, on such a field is pushed into its complement first, so NOT (c < 4) excludes the NULL-struct rows, as c >= 4 does. Java's Parquet reader preserves NULL structs while supplying defaults; GenericReader applies deletes, then evaluates residuals through Accessors. Only the PyArrow row filter changes; projection was already correct. For < and <=, and for NOT over > and >=, Java's generic Evaluator orders NULL first and keeps the NULL-struct rows (pt.c < 6andNOT (pt.c > 6)return rows 1, 2 and 3 there, as on main). This PR follows Arrow, which drops NULLs, as PyIceberg does for NULLs stored in a file.ArrowScan also projects the ancestor structs of filter fields, so filter-after-read (deletes, deletion vectors) can check them; for a file that lacks the filtered field, this reads its parent struct. Arrow field paths are built from field IDs instead of splitting the name on dots, so a struct whose name contains a dot works (the test renames
old.pttonew.pt).Scope: !=, NOT STARTS WITH and NOT NAN on their own keep their main result, and so do NOT (c = 5), NOT (c LIKE 'ab%') and NOT (c IS NAN), which become them. For these the expression evaluator matches NULL and Arrow does not, so their NULL handling is left as it is on main; #4276 (count() and to_arrow() disagree for != on nullable partitions) was closed on Nov 18 and is separate. Java keeps NULL-struct rows for != (
notEqis!eq,Evaluator.java:135-148), sopt.c != 5still differs from Java here. NOT IN now keeps the NULL-struct rows, as Java'snotIn(!in) and a file that stores the NULLs do. NOT over !=, NOT IN, NOT STARTS WITH or NOT NAN is now consistent with =, IN, STARTS WITH and IS NAN. NOT keeps its main result for missing top-level fields and fields with only required ancestors (NOT (d > 4) on a column added without a default still returns every row); changing that is separate.Are these changes tested?
Yes.
test_missing_nested_field_under_null_struct_reads_as_null,test_missing_nested_field_under_renamed_null_structandtest_missing_fields_absent_from_file_read_as_null(tests/io/test_pyarrow.py) fail on main, where the first equality returns all three rows, and pass with this change. Together they cover plain and deletion-vector scans, IN and NOT IN, comparisons, LIKE, IS NAN, NOT over AND and OR, NOT over !=, NOT IN and NOT LIKE, a second optional ancestor, a required struct layer, a missing struct, and a child with a NULL default. They also check that NOT keeps its main result on a missing field without an optional struct ancestor (top level and under a required struct), and filter on a column nameda.band on a present field under the renamednew.ptstruct, which raise ArrowInvalid on main. In a differential check of 98 filters, each of the 43 results this PR changes matches a file that stores the defaults and the NULLs.Are there any user-facing changes?
Yes: these filters now honor NULL ancestors. Binding-time constant folding is unchanged, including required-child IS [NOT] NULL and out-of-range comparisons. Range NOT also changes results for a missing nested field with no default or a NaN default, on any format version and even under a present parent: NOT (pt.n < 4) now returns no rows, as a file that stores the NULLs does. Java agrees for NOT over < and <=, but keeps every row for NOT over > and >=, because it orders NULL first. For a NaN default, Java orders NaN last, so it keeps the present rows for NOT over < and <= and drops them for NOT over > and >=. A filter on a top-level column whose name contains a dot (such as
a.b) no longer raises ArrowInvalid.!=, NOT STARTS WITH and NOT NAN on their own are unchanged.Please add the
changeloglabel.This pull request and its description were written by Isaac.