wgtmac commented on code in PR #1156:
URL: https://github.com/apache/iceberg-cpp/pull/1156#discussion_r4661423929
##########
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:
On libc++, a date upper bound in year 32768 becomes a negative year. With no
lower bound, this can prune a file containing 1970 for `year(d) IN (0, 1)`.
##########
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();
Review Comment:
A v3 file can retain a four-byte date upper bound after promotion to
timestamp. The shared decoder treats the day count as micros or nanos. This bug
predates #1153 and can cause its strict `NOT IN` path to delete files
incorrectly. This patch also exposes the bug in inclusive `IN` when the lower
bound is missing.
##########
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()) {
Review Comment:
Why this line has been changed?
--
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]