deepaknettem commented on code in PR #1156:
URL: https://github.com/apache/iceberg-cpp/pull/1156#discussion_r4676852220
##########
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:
I don't think there's a bug here, but in terms of readability I'm wondering
if we can do something better..
This evaluator is checking **any** row in the file could match the
predicate. Anytime we return false, `constexpr bool kRowCannotMatch = false;`
means we can prune away / skip the entire file.
Since the Literal uses partial ordering, so these comparators `<=` `>=`
could willy nilly return false based on the literal value and the bound values,
and if the values cannot be compared, then incorrectly prune the file.
--
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]