deepaknettem commented on code in PR #1156:
URL: https://github.com/apache/iceberg-cpp/pull/1156#discussion_r4677071286
##########
src/iceberg/expression/inclusive_metrics_evaluator.cc:
##########
@@ -248,31 +248,19 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool>
{
}
ICEBERG_ASSIGN_OR_RAISE(auto lower, LowerBound(expr));
- if (!lower.has_value() || lower->IsNull() || lower->IsNaN()) {
+ if (lower.has_value() && lower->IsNaN()) {
// NaN indicates unreliable bounds. See the InclusiveMetricsEvaluator
docs for more.
return kRowsMightMatch;
}
- auto literals_view = literal_set | std::views::filter([&](const Literal&
lit) {
- return lower.value() <= lit;
- });
- // if all values are less than lower bound, rows cannot match
- if (literals_view.empty()) {
- return kRowCannotMatch;
- }
ICEBERG_ASSIGN_OR_RAISE(auto upper, UpperBound(expr));
- if (!upper.has_value() || upper->IsNull()) {
- return kRowsMightMatch;
- }
- auto filtered_view = literals_view | std::views::filter([&](const Literal&
lit) {
- return upper.value() >= lit;
- });
- // if remaining values are greater than upper bound, rows cannot match
- if (filtered_view.empty()) {
- return kRowCannotMatch;
- }
-
- return kRowsMightMatch;
+ const bool has_lower = lower.has_value() && !lower->IsNull();
+ const bool has_upper = upper.has_value() && !upper->IsNull() &&
!upper->IsNaN();
+ return std::ranges::any_of(literal_set, [&](const Literal& lit) {
+ // Bounds exclude NaN values and may be missing on either side.
+ return lit.IsNaN() ||
+ ((!has_lower || *lower <= lit) && (!has_upper || lit <= *upper));
Review Comment:
thinking through a bit more, perhaps we could structure this check like so:
```
auto outside_bounds = [&](<const Literal& lit>) {
// Logic to check if `lit` is definitely outside bounds..
// If a comparison is unordered or uncertain, return false (treat as
inside bounds) to be safe.
};
return std::ranges::all_of(literal_set, outside_bounds) ? kRowCannotMatch
: kRowsMightMatch;
```
--
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]