gengliangwang opened a new issue, #3836:
URL: https://github.com/apache/iceberg-rust/issues/3836
### Apache Iceberg Rust version
main (`ea17ba2`)
### Describe the bug
`StrictMetricsEvaluator::may_contain_nan`
(`crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs`) returns `true`
when the data file has no NaN count for the column:
```rust
fn may_contain_nan(&self, field_id: i32) -> bool {
if let Some(&nan_count) = self.nan_count(field_id) {
nan_count > 0
} else {
true
}
}
```
NaN counts are only written for `float` and `double` columns
(`NanValueCountVisitor` in this crate, and Iceberg's Java writers), so for a
column of any other type the count is always missing. `visit_inequality`, `eq`
and `r#in` check `may_contain_nan` first and return `ROWS_MIGHT_NOT_MATCH`, so
the evaluator can never report that all rows of a file match `<`, `<=`, `>`,
`>=`, `=` or `IN` on an int, long, date, timestamp, decimal or string column,
whatever the bounds are.
The existing tests pass because their fixtures carry a NaN count for the int
column (`nan_value_counts: HashMap::from([(1, 0), ..])` in `get_test_file_1`
and `get_test_file_eq`), which no writer produces.
Java's `StrictMetricsEvaluator` treats a missing count as "no NaNs":
```java
protected boolean canContainNaNs(int id) {
return nanCounts != null && nanCounts.containsKey(id) && nanCounts.get(id)
> 0;
}
```
### To Reproduce
In the tests of `strict_metrics_evaluator.rs`, drop the NaN count of the int
column and evaluate a predicate that the bounds satisfy:
```rust
let mut file = get_test_file_1(); // id: lower bound 30, upper bound 79, no
nulls
file.nan_value_counts.remove(&1);
let result = StrictMetricsEvaluator::eval(&less_than_int("id", 80),
&file).unwrap();
assert!(result); // fails: the result is false
```
### Expected behavior
A missing NaN count for a column that is not `float` or `double` means that
the column has no NaNs, so the bounds decide. (For `float` and `double` Java
also treats a missing count as "no NaNs"; keeping those as unknown is the more
conservative choice.)
### Willingness to contribute
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]