rahulsmahadev opened a new pull request, #4480:
URL: https://github.com/apache/iceberg-python/pull/4480

   # 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 `pt` is an optional struct, row 2 has 
`pt` NULL, and `pt.c` was added with `initial-default` 5:
   
   ```python
   tbl.scan(row_filter=EqualTo("pt.c", 5)).to_arrow()  # ids [1, 2, 3]; 
expected [1, 3]
   tbl.scan(row_filter=IsNull("pt.c")).to_arrow()      # ids []; expected [2]
   ```
   
   Fix: for =, IN, <, <=, >, >=, IS NULL and IS NOT NULL, 
`translate_column_names` matches 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.pt` to `new.pt` works.
   
   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 (`notEq` is `!eq` and `notIn` is 
`!in`, `Evaluator.java:135-148`), so `pt.c != 5` still 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_struct` and 
`test_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. 
`!=` and `NOT IN` on their own are unchanged.
   
   Please add the `changelog` label.
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to