Repository navigation
Apply initial defaults under present struct parents - #4480
Open
rahulsmahadev wants to merge 1 commit into
Open
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit 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 <no-reply@databricks.com>
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
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, <, <=, >, >=, IS NULL and IS NOT NULL,
translate_column_namesmatches each row by its optional ancestor structs: the default when all of them are present, NULL otherwise. A NOT over one of these predicates, or over != and NOT IN, 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. This fixes Arrow's filter translation and projection. Arrow's < and <= still differ from Java's nulls-first generic evaluator.ArrowScan also projects the ancestor structs of filter fields, so filter-after-read (deletes, deletion vectors) can check them. Arrow field paths are built from field IDs instead of splitting the name on dots, so a struct renamed from
old.pttonew.ptworks.Scope: != and NOT IN on their own keep their main result, and so does NOT (c = 5). 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 them (
notEqis!eqandnotInis!in,Evaluator.java:135-148), sopt.c != 5still differs from Java here. NOT over != or NOT IN is now consistent with = and IN. STARTS WITH and NaN predicates are not changed. NOT keeps its result for missing top-level fields and fields with only required ancestors.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, comparisons, NOT over AND and OR, NOT over != and NOT IN, a second optional ancestor, a required struct layer, a missing struct, and a child with a NULL default.test_translate_column_names_not_on_missing_top_level_column_keeps_its_result(tests/expressions/test_visitors.py) passes on main and pins the top-level NOT.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 missing nested fields defaulting to NULL or NaN, even with a present parent. A filter on a top-level column whose name contains a dot (such as
a.b) no longer raises ArrowInvalid.!=andNOT INon their own are unchanged.Please add the
changeloglabel.This pull request and its description were written by Isaac.