mhatipog opened a new issue, #19110:
URL: https://github.com/apache/iceberg/issues/19110

   ### Apache Iceberg version
   
   1.12.0 (also 1.10.1; same logic on main)
   
   ### Query engine
   
   Spark (3.5.10, 4.0.1, 4.1.4)
   
   ### Please describe the bug
   
   A filter that only references identity partition columns is evaluated by 
Iceberg on partition values and dropped
   from Spark's post-scan filters. If that filter has `<>` under `OR` or `NOT`, 
the NULL partition matches, and the
   query returns rows that SQL excludes.
   
   ```sql
   CREATE TABLE t (id INT, region STRING) USING iceberg PARTITIONED BY (region);
   INSERT INTO t VALUES (1, 'eu'), (2, 'us'), (3, NULL), (4, 'apac');
   
   SELECT id FROM t WHERE region <> 'eu' OR region <> 'us';      -- 1, 2, 3, 4  
 expected 1, 2, 4
   SELECT id FROM t WHERE region = 'eu' OR region <> 'us';       -- 1, 3, 4     
 expected 1, 4
   SELECT count(*) FROM t WHERE region = 'eu' OR region <> 'us'; -- 3           
 expected 2
   SELECT id FROM t WHERE NOT (region = 'eu' AND region IS NULL); -- 1, 2, 3, 4 
 expected 1, 2, 4
   ```
   
   The same table as `USING parquet PARTITIONED BY (region)` returns the 
expected rows, as does an unpartitioned
   Iceberg table. `region <> 'eu'` alone and `region < 'f' OR region > 'u'` are 
correct. INT and DATE partition columns
   behave the same.
   
   The scan has no Filter above it: `BatchScan t [filters=(NOT (region = 'eu') 
OR NOT (region = 'us'))]`.
   
   `SparkScanBuilder.pushPredicates` keeps a predicate out of the post-scan 
filters when
   `ExpressionUtil.selectsPartitions` holds. `SparkV2Filters` converts `<>` to 
`notEqual` and `NOT` to `not(...)`, and
   `notEqual` is true for a NULL value, so the NULL partition is selected and 
Spark never re-checks it. A top-level `<>`
   is correct only because Spark adds `isnotnull` for it. With 
`SparkScanBuilder` patched to always keep the post-scan
   filter, all four queries return the expected rows.
   
   #18605 / #18617 fix the same conversion for metadata deletes and leave scans 
unchanged. I'll open a PR that keeps
   the post-scan filter unless the predicate is NULL-safe.
   
   ### Willingness to contribute
   
   - [x] I can contribute a fix for this bug independently
   


-- 
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