2162174202-sudo opened a new issue, #19264:
URL: https://github.com/apache/iceberg/issues/19264
### Apache Iceberg version
1.12.0 (latest release)
### Query engine
Spark
### Please describe the bug 🐞
In Spark SQL, floating-point comparisons use total ordering where `NaN` is
strictly greater than `+Infinity`, so `CAST('NaN' AS DOUBLE) >= 0.99999999`
evaluates to `TRUE`.
However, when a `>=` (or `>`) filter on a `DOUBLE` / `FLOAT` column is
pushed down to an Iceberg scan in Spark, Iceberg's `InclusiveMetricsEvaluator`
prunes any data file whose column contains only `NaN` values
(`containsNaNsOnly` -> `ROWS_CANNOT_MATCH`), **silently dropping matching `NaN`
rows**.
This creates a direct intra-engine semantic contradiction in Spark:
- Evaluating the predicate in `SELECT` returns `TRUE` for the `NaN` row.
- Keeping the predicate above the Iceberg scan (e.g., in a `JOIN` with
`PushPredicateThroughJoin` excluded) returns the `NaN` row.
- Pushing the predicate into the Iceberg scan silently returns 0 rows.
### Minimal Reproduction
```sql
CREATE TABLE iceberg.default.t_nan_repro (
id INT,
x DOUBLE
) USING iceberg;
INSERT INTO iceberg.default.t_nan_repro
VALUES (1, CAST('NaN' AS DOUBLE));
-- 1. Spark expression evaluation confirms `x >= 0.99999999` is TRUE for NaN:
-- Actual: [[1, NaN, true]]
SELECT
id,
x,
(x >= CAST(0.99999999 AS DOUBLE)) AS ge_res
FROM iceberg.default.t_nan_repro;
-- 2. Same predicate in WHERE pushed to Iceberg silently drops the row:
-- Actual: []
-- Expected: [[1, NaN]]
SELECT id, x
FROM iceberg.default.t_nan_repro
WHERE x >= CAST(0.99999999 AS DOUBLE);
```
### Root Cause Analysis
`SparkV2Filters` translates Spark's `GreaterThan` / `GreaterThanOrEqual`
predicates directly into Iceberg `Expressions.greaterThan` /
`Expressions.greaterThanOrEqual`. During scan planning,
`InclusiveMetricsEvaluator` evaluates `gt` / `gtEq` under IEEE-754 non-matching
`NaN` semantics (pruning files where `containsNaNsOnly(id)` is true), which
conflicts with Spark SQL's total-ordering semantics where `NaN > +Infinity`.
### Expected Behavior
When pushing `>` / `>=` predicates from Spark to Iceberg, data files that
may contain `NaN` values (including all-`NaN` files) should not be pruned so
that pushed-down scans remain semantically equivalent to unpushed Spark SQL
evaluation.
### Willingness to contribute
- [ ] I can contribute a fix for this bug independently
- [x] I would be willing to contribute a fix for this bug with guidance from
the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time
--
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]